Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
schmunk42 committed Dec 21, 2015
1 parent 206ab94 commit f36032d
Show file tree
Hide file tree
Showing 32 changed files with 298 additions and 297 deletions.
11 changes: 6 additions & 5 deletions src/assets/AppAsset.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
/**
* @link http://www.yiiframework.com/
*
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace app\assets;

use yii\helpers\FileHelper;
use yii\web\AssetBundle;

/**
* Configuration for `backend` client script files
* Configuration for `backend` client script files.
*
* @since 4.0
*/
class AppAsset extends AssetBundle
Expand All @@ -27,7 +28,7 @@ class AppAsset extends AssetBundle
public $js = [
'js/app.js',
];

// we recompile the less files from 'yii\bootstrap\BootstrapAsset' and include the css in app.css
// therefore we set bundle to false in application config
public $depends = [
Expand All @@ -44,9 +45,9 @@ public function init()
// This will create a new folder in web/assets for every change and request
// made to the app assets.
if (getenv('APP_ASSET_FORCE_PUBLISH')) {
$files = FileHelper::findFiles(\Yii::getAlias($this->sourcePath));
$files = FileHelper::findFiles(\Yii::getAlias($this->sourcePath));
$mtimes = [];
foreach ($files AS $file) {
foreach ($files as $file) {
$mtimes[] = filemtime($file);
}
touch(\Yii::getAlias($this->sourcePath), max($mtimes));
Expand Down
10 changes: 4 additions & 6 deletions src/assets/SettingsAsset.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace app\assets;

use yii\caching\FileDependency;
Expand Down Expand Up @@ -42,12 +42,11 @@ public function init()
if (isset($config[self::SETTINGS_KEY])) {
$hash = sha1(Json::encode($config[self::SETTINGS_KEY]));
if ($hash !== \Yii::$app->cache->get(self::CACHE_ID)) {

$lessFiles = FileHelper::findFiles($sourcePath, ['only' => ['*.less']]);
foreach ($lessFiles AS $file) {
foreach ($lessFiles as $file) {
unlink($file);
}
foreach ($config[self::SETTINGS_KEY] AS $key => $value) {
foreach ($config[self::SETTINGS_KEY] as $key => $value) {
file_put_contents("$sourcePath/$key.less", $value[0]);
}

Expand All @@ -58,5 +57,4 @@ public function init()
}
}
}

}
}
22 changes: 9 additions & 13 deletions src/commands/AppController.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2014 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace app\commands;

use dektrium\user\Finder;
use mikehaertl\shellcommand\Command;
use yii\console\Controller;


/**
* Task runner command for development.
* @package console\controllers
*
* @author Tobias Munk <tobias@diemeisterei.de>
*/
class AppController extends Controller
{
public $defaultAction = 'version';

/**
* Displays application version from git describe and writes it to `version`
* Displays application version from git describe and writes it to `version`.
*/
public function actionVersion($alias = '@root/version')
{
$this->stdout(\Yii::$app->id.' version '.APP_VERSION);
$this->stdout("\n");
}


/**
* Setup admin user (create, update password, confirm)
* Setup admin user (create, update password, confirm).
*/
public function actionSetupAdminUser()
{
Expand Down Expand Up @@ -62,9 +60,8 @@ public function actionSetupAdminUser()
$this->action('user/confirm', ['admin']);
}


/**
* Clear [application]/web/assets folder
* Clear [application]/web/assets folder.
*/
public function actionClearAssets()
{
Expand All @@ -74,7 +71,7 @@ public function actionClearAssets()
$matchRegex = '"^[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]\?[a-z0-9]$"';

// create $cmd command
$cmd = 'cd "' . $assets . '" && ls | grep -e ' . $matchRegex . ' | xargs rm -rf ';
$cmd = 'cd "'.$assets.'" && ls | grep -e '.$matchRegex.' | xargs rm -rf ';

// Set command
$command = new Command($cmd);
Expand All @@ -87,14 +84,14 @@ public function actionClearAssets()
if ($command->execute()) {
echo "Web assets have been deleted.\n\n";
} else {
echo "\n" . $command->getError() . "\n";
echo "\n".$command->getError()."\n";
echo $command->getStdErr();
}
}
}

/**
* Generate application and required vendor documentation
* Generate application and required vendor documentation.
*/
public function actionGenerateDocs()
{
Expand All @@ -105,7 +102,7 @@ public function actionGenerateDocs()
$commands[] = 'vendor/bin/apidoc api --interactive=0 --exclude=runtime/,tests/,vendor/ . web/apidocs';
$commands[] = 'vendor/bin/apidoc guide --interactive=0 docs web/apidocs';

foreach ($commands AS $command) {
foreach ($commands as $command) {
$cmd = new Command($command);
if ($cmd->execute()) {
echo $cmd->getOutput();
Expand All @@ -118,7 +115,6 @@ public function actionGenerateDocs()
}
}


protected function action($command, $params = [])
{
echo "\nRunning action '$command'...\n";
Expand Down
11 changes: 5 additions & 6 deletions src/components/Helper.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace app\components;


use dektrium\user\models\User as UserModel;
use yii\base\Component;
use yii\helpers\Html;

class Helper extends Component
{
static public function checkApplication()
public static function checkApplication()
{
self::checkUserSetup();
self::checkPagesSetup();
}

static private function checkUserSetup()
private static function checkUserSetup()
{
if (UserModel::find()->where('id != 1')->count() == 0) {
$link = Html::a('user module', ['/user/admin/create']);
Expand All @@ -33,7 +32,7 @@ static private function checkUserSetup()
}
}

static private function checkPagesSetup()
private static function checkPagesSetup()
{
if (!\Yii::$app->getModule('pages')->getLocalizedRootNode()) {
$link = Html::a('pages module', ['/pages']);
Expand All @@ -43,4 +42,4 @@ static private function checkPagesSetup()
);
}
}
}
}
29 changes: 13 additions & 16 deletions src/components/User.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
<?php

namespace app\components;

/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace app\components;

/**
* Class User
* Class User.
*
* Custom user class with additional checks
*
* @package app\components
*/

class User extends \yii\web\User
{
const PUBLIC_ROLE = 'Public';

/**
* Extended permission check with `Guest` role and `route`
* Extended permission check with `Guest` role and `route`.
*
* @param string $permissionName
* @param array $params
* @param string $permissionName
* @param array $params
* @param bool|true $allowCaching
*
* @return bool
*/
public function can($permissionName, $params = [], $allowCaching = true)
{
switch (true) {
case (\Yii::$app->user->identity && \Yii::$app->user->identity->isAdmin):
case \Yii::$app->user->identity && \Yii::$app->user->identity->isAdmin:
return true;
break;
case (!empty($params['route'])):
case !empty($params['route']):
return $this->checkAccessRoute($permissionName, $params, $allowCaching);
break;
default:
Expand All @@ -47,7 +42,7 @@ public function can($permissionName, $params = [], $allowCaching = true)
}

/**
* Checks permissions from guest role, when no user is logged in
* Checks permissions from guest role, when no user is logged in.
*
* @param $permissionName
* @param $params
Expand All @@ -58,11 +53,12 @@ public function can($permissionName, $params = [], $allowCaching = true)
private function canGuest($permissionName, $params, $allowCaching)
{
$guestPermissions = $this->getAuthManager()->getPermissionsByRole(self::PUBLIC_ROLE);

return array_key_exists($permissionName, $guestPermissions);
}

/**
* Checks route permissions
* Checks route permissions.
*
* Splits `permissionName` by underscore and match parts against more global rule
* eg. a permission `app_site` will match, `app_site_foo`
Expand All @@ -89,6 +85,7 @@ private function checkAccessRoute($permissionName, $params, $allowCaching)
}
$routePermission .= '_';
}

return false;
}
}
}
46 changes: 23 additions & 23 deletions src/config/assets-prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@
*/
return [
// Adjust command/callback for JavaScript files compressing:
'jsCompressor' => 'java -jar /root/compiler.jar --js {from} --js_output_file {to}',
'jsCompressor' => 'java -jar /root/compiler.jar --js {from} --js_output_file {to}',
// Adjust command/callback for CSS files compressing:
'cssCompressor' => 'yui-compressor --type css {from} -o {to}',
// The list of asset bundles to compress:
'bundles' => [
'bundles' => [
'app\assets\AppAsset',
'app\modules\backend\assets\AdminAsset',
\dmstr\web\AdminLteAsset::className()
\dmstr\web\AdminLteAsset::className(),
],
// Asset bundle for compression output:
'targets' => [
'targets' => [
'frontend' => [
'class' => 'yii\web\AssetBundle',
'class' => 'yii\web\AssetBundle',
'basePath' => '@app/../web/assets-prod',
'baseUrl' => '@web/assets-prod',
'js' => 'js/frontend-{hash}.js',
'css' => 'css/frontend-{hash}.css',
'depends' => [
'baseUrl' => '@web/assets-prod',
'js' => 'js/frontend-{hash}.js',
'css' => 'css/frontend-{hash}.css',
'depends' => [
// Include only 'frontend' assets:
'app\assets\AppAsset',
],
],
'backend' => [
'class' => 'yii\web\AssetBundle',
'class' => 'yii\web\AssetBundle',
'basePath' => '@app/../web/assets-prod',
'baseUrl' => '@web/assets-prod',
'js' => 'js/backend-{hash}.js',
'css' => 'css/backend-{hash}.css',
'depends' => [
'baseUrl' => '@web/assets-prod',
'js' => 'js/backend-{hash}.js',
'css' => 'css/backend-{hash}.css',
'depends' => [
// Include only 'backend' assets:
'app\modules\backend\assets\AdminAsset',
\dmstr\web\AdminLteAsset::className()
\dmstr\web\AdminLteAsset::className(),
],
],
'all' => [
'class' => 'yii\web\AssetBundle',
'all' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@app/../web/assets-prod',
'baseUrl' => '@web/assets-prod',
'js' => 'js/all-{hash}.js',
'css' => 'css/all-{hash}.css',
'baseUrl' => '@web/assets-prod',
'js' => 'js/all-{hash}.js',
'css' => 'css/all-{hash}.css',
],
],
// Asset manager configuration:
'assetManager' => [
'assetManager' => [
'basePath' => '/app/web/assets-prod',
'baseUrl' => '/assets-prod'
'baseUrl' => '/assets-prod',
],
];
];
Loading

0 comments on commit f36032d

Please sign in to comment.