-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f6cb6a
commit c7aec4a
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace yii1tech\di\web; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
class Controller extends \CController | ||
{ | ||
use CreatesActionViaDI; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace yii1tech\di\web; | ||
|
||
use CException; | ||
use Yii; | ||
use yii1tech\di\DI; | ||
|
||
/** | ||
* @mixin \CController | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
trait CreatesActionViaDI | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createAction($actionID) | ||
{ | ||
if ($actionID === '') { | ||
$actionID = $this->defaultAction; | ||
} | ||
|
||
if (method_exists($this, 'action' . $actionID) && strcasecmp($actionID, 's')) {// we have actions method | ||
return new InlineAction($this, $actionID); | ||
} | ||
|
||
return parent::createAction($actionID); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createActionFromMap($actionMap, $actionID, $requestActionID, $config = []) | ||
{ | ||
if(($pos = strpos($actionID, '.')) === false && isset($actionMap[$actionID])) { | ||
$config = array_merge( | ||
is_array($actionMap[$actionID]) ? $actionMap[$actionID] : ['class' => $actionMap[$actionID]], | ||
$config | ||
); | ||
|
||
if (isset($config['class'])) { | ||
$class = $config['class']; | ||
unset($config['class']); | ||
} else { | ||
throw new CException(Yii::t('yii', 'Object configuration must be an array containing a "class" element.')); | ||
} | ||
|
||
$action = DI::make($class, [ | ||
'controller' => $this, | ||
'id' => $requestActionID, | ||
]); | ||
|
||
foreach ($config as $name => $value) { | ||
$action->$name = $value; | ||
} | ||
|
||
return $action; | ||
} | ||
|
||
return parent::createActionFromMap($actionMap, $actionID, $requestActionID, $config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace yii1tech\di\web; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
class InlineAction extends \CInlineAction | ||
{ | ||
|
||
} |