Skip to content

Commit

Permalink
Controller/Lead enables to DI
Browse files Browse the repository at this point in the history
  • Loading branch information
ysugimoto committed Nov 15, 2012
1 parent 5461b95 commit 519994c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions seezoo/core/classes/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ public function helper($helpers, $alias = FALSE)

foreach ( (array)$helpers as $helper )
{
$name = str_replace('Helper', '', $helper);
$name = str_replace(Seezoo::getPackage('helper'), '', $helper);
$alias = ( $alias ) ? $alias : ucfirst($name);
$module = $this->loadModule($name, 'helpers', TRUE, array(), $alias);
$module = $this->loadModule($helper, TRUE, array(), $alias);

$H->{strtolower($name)} = $module->data;
}
Expand Down
7 changes: 2 additions & 5 deletions seezoo/core/classes/Kennel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
class SZ_Kennel
{
protected $table;
protected $modelSuffixRegex;


public function __construct()
{
$this->modelSuffixRegex = '#' . preg_quote(get_config('model_suffix')) . '$#';

// Database autoloaded if "db" property is declared
if ( property_exists($this, 'db') )
{
Expand All @@ -42,9 +39,9 @@ public function __get($name)
{
return Seezoo::$Importer->database();
}
else if ( preg_match($this->modelSuffixRegex, $name) )
else if ( preg_match('/'. implode('|', Seezoo::getSuffix('model')) . '$/', $name) )
{
return Seezoo::$Importer->model($name);
return Seezoo::$Importer->model(Seezoo::removePrefix($name));
}
}

Expand Down
1 change: 1 addition & 0 deletions seezoo/core/classes/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function call($params = array(), $autoAssign = TRUE)
{
if ( method_exists($this, $this->_callInfo) )
{
DI::make($this)->inject($this->_callInfo);
$data = call_user_func_array(array($this, $this->_callInfo), $params);
if ( $autoAssign === TRUE )
{
Expand Down
7 changes: 6 additions & 1 deletion seezoo/core/classes/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public function bootProcess()
*/
public function bootLead()
{
return Seezoo::$Importer->lead($this->_directory . $this->_class);
$lead = Seezoo::$Importer->lead($this->_directory . $this->_class);
DI::make($lead)->inject('__construct');
return $lead;
}


Expand Down Expand Up @@ -319,6 +321,9 @@ public function bootController($extraArgs = FALSE)
$Controller = new $class();
$Controller->lead->prepare();

// Deendency injection
DI::make($Controller)->inject('__construct');

// under-score prefixed method cannot execute.
if ( preg_match('/^_.+$/u', $this->_method) )
{
Expand Down
9 changes: 5 additions & 4 deletions seezoo/core/system/DI.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public static function make($instance)
* @access private
* @param object $instance
*/
private function __construct($instance)
private function __construct(&$instance)
{
$this->instance = $instance;
$this->instance = $instance;
$this->className = get_class($instance);
}

Expand Down Expand Up @@ -127,6 +127,7 @@ public function inject($methodName = '', $diInstance = NULL)
}
foreach ( explode(',', $docs['di:' . $di]) as $module )
{
$module = trim($module);
$mod = lcfirst($module);
if ( ! property_exists($this->instance, $mod) )
{
Expand Down Expand Up @@ -167,11 +168,11 @@ public function getInstance()
private function _parseAnnotation($docc)
{
$ret = array();
if ( preg_match_all('/@(.+)/u', $docc, $matches) )
if ( preg_match_all('/@(.+)/u', $docc, $matches, PREG_PATTERN_ORDER) )
{
foreach ( $matches[1] as $line )
{
list($key, $value) = explode(' ', $line, 2);
list($key, $value) = explode(' ', trim($line), 2);
$ret[$key] = $value;
}
}
Expand Down

0 comments on commit 519994c

Please sign in to comment.