コード例 #1
0
 public function addBeanDefinition(BeanDefinition $definition)
 {
     if (array_key_exists($definition->getId(), $this->beanDefinitions)) {
         throw new IocException("Bean ({$definition->getId()}) already defined");
     }
     $this->beanDefinitions[$definition->getId()] = $definition;
     if (!$definition->isLazyInit()) {
         $this->beanToInitialize[] = $definition->getId();
     }
 }
コード例 #2
0
 /**
  * inject a value in the property field of the instance, scan for a setter then a property
  * @param $instance Object
  * @param $propertyName String
  * @param $value Object
  * @return 
  */
 private function injectProperty($instance, $value, BeanDefinition $bean)
 {
     $propertyName = $this->name;
     $setter = 'set' . ucfirst($propertyName);
     if (method_exists($instance, $setter)) {
         $instance->{$setter}($value);
     } else {
         if (property_exists($instance, $propertyName)) {
             $instance->{$propertyName} = $value;
         } else {
             throw new IocException("cannot find setter ({$setter}) nor property ({$propertyName}) for bean ({$bean->getId()})");
         }
     }
 }
コード例 #3
0
 /**
  * Check if the bean have an init method and execute it
  * @param $instance
  * @return unknown_type
  */
 private function doInit($instance, BeanDefinition $bean)
 {
     $init = $bean->getInitMethod();
     if ($init != '') {
         if (method_exists($instance, $init)) {
             $instance->{$init}();
         } else {
             throw new IocException("cannot find method ({$init}) defined in (init-method) of bean ({$bean->getId()})");
         }
     }
 }