Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug correction in ServiceContainerLoaderAnnotations.
No more issue when a service property or method does not have a docblock comment.
- Loading branch information
1 parent
f798e9f
commit 0370dcd
Showing
4 changed files
with
69 additions
and
69 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
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
126 changes: 63 additions & 63 deletions
126
library/LoSo/Zend/Controller/Action/Helper/DependencyInjection.php
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 |
---|---|---|
@@ -1,63 +1,63 @@ | ||
<?php | ||
/** | ||
* Description of DependencyInjection | ||
* | ||
* @author Loïc Frering <loic.frering@gmail.com> | ||
*/ | ||
class LoSo_Zend_Controller_Action_Helper_DependencyInjection extends Zend_Controller_Action_Helper_Abstract | ||
{ | ||
/** | ||
* | ||
* @var sfServiceContainer | ||
*/ | ||
protected $_container; | ||
|
||
public function preDispatch() | ||
{ | ||
$actionController = $this->getActionController(); | ||
$this->_container = $actionController->getInvokeArg('bootstrap')->getContainer(); | ||
|
||
$r = new Zend_Reflection_Class($actionController); | ||
$properties = $r->getProperties(); | ||
|
||
foreach($properties as $property) { | ||
if($property->getDeclaringClass()->getName() == get_class($actionController)) { | ||
if($property->getDocComment()->hasTag('Inject')) { | ||
$injectTag = $property->getDocComment()->getTag('Inject'); | ||
$serviceName = $injectTag->getDescription(); | ||
if(empty($serviceName)) { | ||
$serviceName = $this->_formatServiceName($property->getName()); | ||
} | ||
if($this->_container->hasService($serviceName)) { | ||
$property->setAccessible(true); | ||
$property->setValue($actionController, $this->_container->getService($serviceName)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
protected function _formatServiceName($serviceName) | ||
{ | ||
if(strpos($serviceName, '_') === 0) { | ||
$serviceName = substr($serviceName, 1); | ||
} | ||
return $serviceName; | ||
} | ||
|
||
public function direct($name) | ||
{ | ||
if($this->_container->hasService($name)) { | ||
return $this->_container->getService($name); | ||
} | ||
else if($this->_container->hasParameter($name)) { | ||
return $this->_container->getParameter($name); | ||
} | ||
return null; | ||
} | ||
|
||
public function getContainer() { | ||
return $this->_container; | ||
} | ||
} | ||
<?php | ||
/** | ||
* Description of DependencyInjection | ||
* | ||
* @author Loïc Frering <loic.frering@gmail.com> | ||
*/ | ||
class LoSo_Zend_Controller_Action_Helper_DependencyInjection extends Zend_Controller_Action_Helper_Abstract | ||
{ | ||
/** | ||
* | ||
* @var sfServiceContainer | ||
*/ | ||
protected $_container; | ||
|
||
public function preDispatch() | ||
{ | ||
$actionController = $this->getActionController(); | ||
$this->_container = $actionController->getInvokeArg('bootstrap')->getContainer(); | ||
|
||
$r = new Zend_Reflection_Class($actionController); | ||
$properties = $r->getProperties(); | ||
|
||
foreach($properties as $property) { | ||
if($property->getDeclaringClass()->getName() == get_class($actionController)) { | ||
if($property->getDocComment() && $property->getDocComment()->hasTag('Inject')) { | ||
$injectTag = $property->getDocComment()->getTag('Inject'); | ||
$serviceName = $injectTag->getDescription(); | ||
if(empty($serviceName)) { | ||
$serviceName = $this->_formatServiceName($property->getName()); | ||
} | ||
if($this->_container->hasService($serviceName)) { | ||
$property->setAccessible(true); | ||
$property->setValue($actionController, $this->_container->getService($serviceName)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
protected function _formatServiceName($serviceName) | ||
{ | ||
if(strpos($serviceName, '_') === 0) { | ||
$serviceName = substr($serviceName, 1); | ||
} | ||
return $serviceName; | ||
} | ||
|
||
public function direct($name) | ||
{ | ||
if($this->_container->hasService($name)) { | ||
return $this->_container->getService($name); | ||
} | ||
else if($this->_container->hasParameter($name)) { | ||
return $this->_container->getParameter($name); | ||
} | ||
return null; | ||
} | ||
|
||
public function getContainer() { | ||
return $this->_container; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> | ||
</project-private> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> | ||
</project-private> |