Skip to content

Commit

Permalink
Bug correction in ServiceContainerLoaderAnnotations.
Browse files Browse the repository at this point in the history
No more issue when a service property or method does not have a docblock comment.
  • Loading branch information
loicfrering committed Mar 15, 2010
1 parent f798e9f commit 0370dcd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion application/configs/application.ini
Expand Up @@ -30,4 +30,4 @@ phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

bootstrap.container.symfony.cache = true
bootstrap.container.symfony.cache = false
Expand Up @@ -90,7 +90,7 @@ protected function _reflectProperties(Zend_Reflection_Class $r, sfServiceDefinit
{
$properties = $r->getProperties();
foreach($properties as $property) {
if($property->getDeclaringClass()->getName() == $r->getName()) {
if($property->getDocComment() && $property->getDeclaringClass()->getName() == $r->getName()) {
$docblock = $property->getDocComment();
foreach($this->_annotations as $annotation) {
if($docblock->hasTag($annotation->getName())) {
Expand Down
126 changes: 63 additions & 63 deletions library/LoSo/Zend/Controller/Action/Helper/DependencyInjection.php
@@ -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;
}
}
8 changes: 4 additions & 4 deletions nbproject/private/private.xml
@@ -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>

0 comments on commit 0370dcd

Please sign in to comment.