Skip to content

Commit b315b7d

Browse files
committed
base structure
1 parent 3785ff0 commit b315b7d

31 files changed

+1241
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"psr-4": {
1717
"nullref\\cms\\": "src/"
1818
}
19+
},
20+
"extra": {
21+
"bootstrap":"nullref\\cms\\Bootstrap"
1922
}
2023
}

src/Bootstrap.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace nullref\cms;
4+
5+
6+
use yii\base\Application;
7+
use yii\base\BootstrapInterface;
8+
9+
class Bootstrap implements BootstrapInterface
10+
{
11+
public function bootstrap($app)
12+
{
13+
$prefix = $app->getModule('cms')->urlPrefix;
14+
$app->urlManager->addRules([
15+
$prefix.'/<route:[a-zA-Z0-9-/]+>' => '/cms/page/index'
16+
]);
17+
}
18+
19+
}

src/Module.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
use nullref\core\components\Module as BaseModule;
66
use nullref\core\interfaces\IAdminModule;
77
use Yii;
8+
use yii\base\InvalidConfigException;
89

910
/**
1011
* Class Module
1112
* @package nullref\blog
1213
*/
1314
class Module extends BaseModule implements IAdminModule
1415
{
16+
public $urlPrefix = '/pages';
17+
18+
public $blockManagerClass = 'nullref\cms\components\BlockManager';
19+
20+
public function init()
21+
{
22+
parent::init();
23+
24+
$this->setComponents([
25+
'blockManager' => $this->blockManagerClass,
26+
]);
27+
}
28+
1529
public static function getAdminMenu()
1630
{
1731
return [

src/blocks/html/Block.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace nullref\cms\blocks\html;
4+
5+
use nullref\cms\components\Block as BaseBlock;
6+
/**
7+
* Class Block
8+
*/
9+
class Block extends BaseBlock
10+
{
11+
public $content;
12+
13+
public function getName()
14+
{
15+
return 'HTML Block';
16+
}
17+
18+
public function rules()
19+
{
20+
return [
21+
[['content'],'required'],
22+
];
23+
}
24+
25+
public function getConfig()
26+
{
27+
return [
28+
'content'=>$this->content,
29+
];
30+
}
31+
32+
33+
}

src/blocks/html/Widget.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace nullref\cms\blocks\html;
7+
8+
use nullref\cms\components\Widget as BaseWidget;
9+
use yii\helpers\Html;
10+
11+
12+
class Widget extends BaseWidget
13+
{
14+
public $content;
15+
16+
public function run()
17+
{
18+
return Html::encode($this->content);
19+
}
20+
}

src/blocks/html/_form.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* @var $form \yii\widgets\ActiveForm
4+
* @var $block \nullref\cms\blocks\html\Block
5+
*/
6+
7+
echo $form->field($block, 'content')->textarea();

src/blocks/text/Block.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace nullref\cms\blocks\text;
4+
5+
use nullref\cms\components\Block as BaseBlock;
6+
/**
7+
* Class Block
8+
*/
9+
class Block extends BaseBlock
10+
{
11+
public $content;
12+
13+
public function getName()
14+
{
15+
return 'Text Block';
16+
}
17+
18+
public function rules()
19+
{
20+
return [
21+
[['content'],'required'],
22+
];
23+
}
24+
25+
26+
public function getConfig()
27+
{
28+
return [
29+
'content'=>$this->content,
30+
];
31+
}
32+
}

src/blocks/text/Widget.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace nullref\cms\blocks\text;
7+
8+
use nullref\cms\components\Widget as BaseWidget;
9+
use yii\helpers\Html;
10+
11+
12+
class Widget extends BaseWidget
13+
{
14+
public $content;
15+
16+
public function run()
17+
{
18+
return Html::encode($this->content);
19+
}
20+
}

src/blocks/text/_form.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* @var $form \yii\widgets\ActiveForm
4+
* @var $block \nullref\cms\blocks\text\Block
5+
*/
6+
7+
echo $form->field($block, 'content')->textarea();

src/components/Block.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace nullref\cms\components;
4+
5+
6+
use yii\base\Model;
7+
use yii\base\Widget;
8+
9+
abstract class Block extends Model
10+
{
11+
public $form = '_form.php';
12+
13+
public abstract function getName();
14+
15+
protected function getDir() {
16+
$reflector = new \ReflectionClass(get_class($this));
17+
return dirname($reflector->getFileName());
18+
}
19+
20+
public function getForm()
21+
{
22+
return realpath($this->getDir().'/'.$this->form);
23+
}
24+
25+
public abstract function getConfig();
26+
}

0 commit comments

Comments
 (0)