Skip to content

Commit

Permalink
added GettersTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Apr 27, 2017
1 parent 3fb2148 commit 6153121
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 50 deletions.
45 changes: 6 additions & 39 deletions src/base/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,18 @@
use yii\base\ViewContextInterface;

/**
* Base for components.
*/
class Component extends \yii\base\Component implements ViewContextInterface
{
use GettersTrait;

public function render($view, $params = [])
{
return Yii::$app->getView()->render($view, array_merge([
'module' => $this,
'config' => Yii::$app->get('config'),
'app' => Yii::$app,
'config' => Yii::$app,
'component' => $this,
], $params), $this);
}

public function getViewPath()
{
die(__METHOD__);
return '';
}

protected $_view;

public function getView()
{
if ($this->_view === null) {
$this->_view = Yii::$app->getView();
}

return $this->_view;
}

public function takeGoal($id)
{
return Yii::$app->get($id);
}

public function takeVendor()
{
return Yii::$app->get('vendor');
}

public function takePackage()
{
return Yii::$app->get('package');
}

public function takeVcs()
{
return Yii::$app->get('git');
}
}
14 changes: 3 additions & 11 deletions src/base/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,9 @@
/**
* Basic controller.
*/
class Controller extends \yii\console\Controller
abstract class Controller extends \yii\console\Controller
{
public $layout = false;

public function getConfiguration()
{
return $this->getModule()->getConfiguration();
}
use GettersTrait;

public function getModule()
{
return $this->module;
}
public $layout = false;
}
63 changes: 63 additions & 0 deletions src/base/GettersTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Automation tool mixed with code generator for easier continuous development
*
* @link https://github.com/hiqdev/hidev
* @package hidev
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
*/

namespace hidev\base;

use ReflectionClass;
use Yii;

/**
* Getters trait.
*/
trait GettersTrait
{
protected $_view;

public function getView()
{
if ($this->_view === null) {
$this->_view = $this->getApp()->getView();
}

return $this->_view;
}

public function getViewPath()
{
$ref = new ReflectionClass($this);

return dirname(dirname($ref->getFileName())) . '/views';
}

public function takeGoal($id)
{
return $this->getApp()->get($id);
}

public function takeVendor()
{
return $this->getApp()->get('vendor');
}

public function takePackage()
{
return $this->getApp()->get('package');
}

public function takeVcs()
{
return $this->getApp()->get('git');
}

public function getApp()
{
return Yii::$app;
}
}

0 comments on commit 6153121

Please sign in to comment.