Skip to content

Commit fbbf742

Browse files
committed
global refactoring
1 parent 89ed9ff commit fbbf742

24 files changed

+193
-49
lines changed

composer.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@
88
],
99
"minimum-stability": "dev",
1010
"require": {
11-
"yiisoft/yii2": "*",
12-
"yiisoft/yii2-jui": "~2.0.0",
11+
"bower-asset/owl.carousel": "2.*",
1312
"mihaildev/yii2-ckeditor": "*",
1413
"mihaildev/yii2-elfinder": "*",
15-
"nullref/yii2-useful": "*",
16-
"nullref/yii2-core": "*",
17-
"bower-asset/owl.carousel": "2.*",
14+
"nullref/yii2-core": "^0.0.3",
15+
"nullref/yii2-useful": ">=0.0.4",
16+
"rmrevin/yii2-fontawesome": ">=2.16.0",
1817
"trntv/yii2-aceeditor": "*",
1918
"unclead/yii2-multiple-input": ">=1.2.10",
2019
"wbraganca/yii2-fancytree-widget": "1.0.1",
21-
"rmrevin/yii2-fontawesome": ">=2.16.0"
20+
"yiisoft/yii2": ">=2.0.13",
21+
"yiisoft/yii2-bootstrap": "^2.0@dev",
22+
"yiisoft/yii2-jui": "~2.0.0"
23+
},
24+
"require-dev": {
25+
"yiisoft/yii2-gii": "^2.0@dev"
26+
},
27+
"config": {
28+
"sort-packages": true
2229
},
2330
"autoload": {
2431
"psr-4": {

src/Bootstrap.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
use Yii;
77
use yii\base\BootstrapInterface;
88
use yii\base\Event;
9-
use yii\gii\Module as Gii;
109
use yii\i18n\PhpMessageSource;
1110
use yii\web\Application as WebApplication;
1211

1312
class Bootstrap implements BootstrapInterface
1413
{
14+
/**
15+
* Map of classes possible that could be override
16+
*
17+
* @var array
18+
*/
1519
protected $classMap = [
1620
'Block' => 'nullref\cms\models\Block',
1721
'BlockQuery' => 'nullref\cms\models\BlockQuery',
@@ -20,23 +24,35 @@ class Bootstrap implements BootstrapInterface
2024
'PageQuery' => 'nullref\cms\models\PageQuery',
2125
];
2226

27+
/**
28+
* Check if application has cms module, if has:
29+
* - add module classes to application container
30+
* - add url rule for cms pages
31+
* - add elFinder controller
32+
* - add i18n for module
33+
* - add custom generators to gii
34+
*
35+
* @param \yii\base\Application $app
36+
* @throws \yii\base\InvalidConfigException
37+
*/
2338
public function bootstrap($app)
2439
{
2540
/** @var Module $module */
2641
if ($app->hasModule('cms') && ($module = $app->getModule('cms')) instanceof Module) {
2742
$classMap = array_merge($this->classMap, $module->classMap);
2843
foreach (array_keys($this->classMap) as $item) {
2944
$className = '\nullref\cms\models\\' . $item;
30-
$cmsClass = $className::className();
3145
$definition = $classMap[$item];
32-
Yii::$container->set($cmsClass, $definition);
46+
Yii::$container->set($className, $definition);
3347
}
48+
3449
if ($app instanceof WebApplication) {
35-
$prefix = $app->getModule('cms')->urlPrefix;
50+
$prefix = $module->urlPrefix;
3651
$app->urlManager->addRules([Yii::createObject([
37-
'class' => PageUrlRule::className(),
52+
'class' => PageUrlRule::class,
3853
'pattern' => $prefix . '/<route:[_a-zA-Z0-9-/]+>',
3954
])]);
55+
4056
if (!isset($app->controllerMap['elfinder-backend'])) {
4157
$app->controllerMap['elfinder-backend'] = [
4258
'class' => 'mihaildev\elfinder\Controller',
@@ -64,13 +80,14 @@ public function bootstrap($app)
6480
}
6581

6682
$app->i18n->translations['cms*'] = [
67-
'class' => PhpMessageSource::className(),
83+
'class' => PhpMessageSource::class,
6884
'basePath' => '@nullref/cms/messages',
6985
];
7086
}
71-
if (YII_ENV_DEV) {
72-
Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
73-
/** @var Gii $gii */
87+
88+
if ($app->hasModule('gii')) {
89+
Event::on(\yii\gii\Module::class, yii\gii\Module::EVENT_BEFORE_ACTION, function (Event $event) {
90+
/** @var \yii\gii\Module $gii */
7491
$gii = $event->sender;
7592
$gii->generators['block-migration-generator'] = [
7693
'class' => 'nullref\cms\generators\block_migration\Generator',

src/Module.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace nullref\cms;
44

5-
use nullref\cms\components\PageLayoutManager;
65
use nullref\core\components\Module as BaseModule;
76
use nullref\core\interfaces\IAdminModule;
87
use Yii;
@@ -13,7 +12,7 @@
1312
* @package nullref\blog
1413
*
1514
*
16-
* @property PageLayoutManager $layoutManager
15+
* @property components\PageLayoutManager $layoutManager
1716
*
1817
*/
1918
class Module extends BaseModule implements IAdminModule
@@ -26,21 +25,33 @@ class Module extends BaseModule implements IAdminModule
2625

2726
public $urlPrefix = '/pages';
2827

28+
/**
29+
* Module constructor.
30+
* Init with inner components
31+
*
32+
* @param $id
33+
* @param null $parent
34+
* @param array $config
35+
*/
2936
public function __construct($id, $parent = null, $config = [])
3037
{
3138
$config = ArrayHelper::merge([
3239
'components' => [
3340
'layoutManager' => [
34-
'class' => '\nullref\cms\components\PageLayoutManager',
41+
'class' => components\PageLayoutManager::class,
3542
],
3643
'blockManager' => [
37-
'class' => 'nullref\cms\components\BlockManager',
44+
'class' => components\BlockManager::class,
3845
],
3946
],
4047
], $config);
4148
parent::__construct($id, $parent, $config);
4249
}
4350

51+
/**
52+
* Return module menu for admin module
53+
* @return array
54+
*/
4455
public static function getAdminMenu()
4556
{
4657
return [

src/actions/PageView.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@
1010

1111

1212
/**
13+
* Class PageView
14+
* @package nullref\cms\actions
15+
*
16+
* Action for rendering cms pages
17+
*
1318
* @author Dmytro Karpovych
1419
* @copyright 2015 NRE
1520
*/
1621
class PageView extends Action
1722
{
1823
public $view = 'view';
1924

25+
/**
26+
* @return string
27+
* @throws NotFoundHttpException
28+
* @throws \Exception
29+
* @throws \Throwable
30+
*/
2031
public function run()
2132
{
2233
if (($route = Yii::$app->request->getQueryParam('route')) == null) {

src/blocks/carousel/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
?>
1515

16-
<?= $form->field($block, 'content')->widget(CKEditor::className(), [
16+
<?= $form->field($block, 'content')->widget(CKEditor::class, [
1717
'id' => 'editor',
1818
'editorOptions' => [
1919
'preset' => 'full',

src/blocks/html/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@
6060

6161
$editorConfig['editorOptions'] = ElFinder::ckeditorOptions('elfinder-backend', $editorConfig['editorOptions']);
6262

63-
echo $form->field($block, 'content')->widget(CKEditor::className(), $editorConfig);
63+
echo $form->field($block, 'content')->widget(CKEditor::class, $editorConfig);
6464
echo $form->field($block, 'tag')->textInput();
6565
echo $form->field($block, 'tagClass')->textInput();

src/blocks/image/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @var $block \nullref\cms\blocks\text\Block
88
*/
99

10-
echo $form->field($block, 'image')->widget(InputFile::className(), [
10+
echo $form->field($block, 'image')->widget(InputFile::class, [
1111
'language' => 'ru',
1212
'controller' => 'elfinder-backend',
1313
'filter' => 'image',

src/blocks/php/_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@
6262

6363
$editorConfig['editorOptions'] = ElFinder::ckeditorOptions('elfinder-backend', $editorConfig['editorOptions']);
6464

65-
echo $form->field($block, 'content')->widget(CKEditor::className(), $editorConfig);
65+
echo $form->field($block, 'content')->widget(CKEditor::class, $editorConfig);
6666
echo $form->field($block, 'tag')->textInput();
6767
echo $form->field($block, 'tagClass')->textInput();

src/components/Block.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ abstract class Block extends Model
1717
* @param array $config
1818
* @param string $moduleId
1919
* @return Widget
20+
* @throws \Exception
21+
* @throws \yii\base\InvalidConfigException
2022
*/
2123
public static function getBlock($blockId, $config = [], $moduleId = 'cms')
2224
{
@@ -25,26 +27,41 @@ public static function getBlock($blockId, $config = [], $moduleId = 'cms')
2527

2628
/**
2729
* @param string $moduleId
28-
* @return BlockManager
30+
* @return null|BlockManager
2931
*/
3032
public static function getManager($moduleId = 'cms')
3133
{
3234
return \Yii::$app->getModule($moduleId)->get('blockManager');
3335
}
3436

37+
/**
38+
* Return name of block
39+
* @return mixed
40+
*/
3541
public abstract function getName();
3642

43+
/**
44+
* Return path to form class
45+
* @return bool|string
46+
*/
3747
public function getForm()
3848
{
3949
return realpath($this->getDir() . '/' . $this->formFile);
4050
}
4151

52+
/**
53+
* Get path to directory with block classes
54+
* @return string
55+
*/
4256
protected function getDir()
4357
{
4458
$reflector = new \ReflectionClass(get_class($this));
4559
return dirname($reflector->getFileName());
4660
}
4761

62+
/**
63+
* @return array
64+
*/
4865
public function getConfig()
4966
{
5067
return $this->getAttributes(null, ['formFile']);

src/components/BlockManager.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
use yii\caching\TagDependency;
1010
use yii\helpers\ArrayHelper;
1111

12+
/**
13+
* Class BlockManager
14+
* Contain list of blocks and management creation of block widgets
15+
*
16+
* @package nullref\cms\components
17+
*/
1218
class BlockManager extends Component
1319
{
1420
const CLASS_WIDGET = '\Widget';
@@ -39,10 +45,14 @@ public function register($id, $namespace)
3945
}
4046

4147
/**
48+
* Create instance of block widget by block id
49+
*
4250
* @param $id
4351
* @param $config
44-
* @return \nullref\cms\components\Widget
45-
* @throws \yii\base\InvalidConfigException | \Exception
52+
* @return Widget
53+
* @throws InvalidConfigException
54+
* @throws \Exception
55+
* @throws \Throwable
4656
*/
4757
public function getWidget($id, $config = [])
4858
{
@@ -71,6 +81,7 @@ public function getWidget($id, $config = [])
7181
}
7282

7383
/**
84+
* Return current list of blocks in system
7485
* @return array
7586
*/
7687
public function getList()

0 commit comments

Comments
 (0)