Ejemplo n.º 1
0
 /**
  * Configure an identifier
  *
  * @param ObjectIdentifier $identifier
  * @param array             $data
  * @return ObjectConfig
  */
 protected function _configure(ObjectIdentifier $identifier, array $data = array())
 {
     //Prevent config settings from being stored in the identifier
     $config = clone $identifier->getConfig();
     //Append the config data from the singleton
     if ($identifier->getType() != 'lib' && $this->isSingleton($identifier)) {
         $parts = $identifier->toArray();
         unset($parts['type']);
         unset($parts['domain']);
         unset($parts['package']);
         //Append the config from the singleton
         $config->append($this->getIdentifier($parts)->getConfig());
     }
     //Append the config data for the object
     $config->append($data);
     //Set the service container and identifier
     $config->object_manager = $this;
     $config->object_identifier = $identifier;
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * Configure an identifier
  *
  * @param ObjectIdentifier $identifier
  * @param array $config
  * @return ObjectConfig
  */
 protected function _configure(ObjectIdentifier $identifier, $data)
 {
     //Prevent config settings from being stored in the identifier
     $config = clone $identifier->getConfig();
     //Merge the config data
     $config->append($data);
     //Set the service container and identifier
     $config->object_manager = $this;
     $config->object_identifier = $identifier;
     return $config;
 }
Ejemplo n.º 3
0
 /**
  * Get an instance of a class based on a class identifier
  *
  * @param   ObjectIdentifier $identifier
  * @param   array            $config    An optional associative array of configuration settings.
  * @throws	ObjectExceptionInvalidObject	  If the object doesn't implement the ObjectInterface
  * @throws  ObjectExceptionNotFound           If object cannot be loaded
  * @throws  ObjectExceptionNotInstantiated    If object cannot be instantiated
  * @return  object  Return object on success, throws exception on failure
  */
 protected function _instantiate(ObjectIdentifier $identifier, array $config = array())
 {
     $result = null;
     if ($this->getClassLoader()->loadClass($identifier->classname)) {
         if (!$identifier->inherits(__NAMESPACE__ . '\\ObjectInterface', false)) {
             throw new ObjectExceptionInvalidObject('Object: ' . $identifier->classname . ' does not implement ObjectInterface');
         }
         //Configure the identifier
         $config = $this->_configure($identifier, $config);
         // Delegate object instantiation.
         if ($identifier->inherits(__NAMESPACE__ . '\\ObjectInstantiable', false)) {
             $result = call_user_func(array($identifier->classname, 'getInstance'), $config, $this);
         } else {
             $result = new $identifier->classname($config);
         }
         //Thrown an error if no object was instantiated
         if (!is_object($result)) {
             throw new ObjectExceptionNotInstantiated('Cannot instantiate object from identifier: ' . $identifier->classname);
         }
     } else {
         throw new ObjectExceptionNotFound('Cannot load object from identifier: ' . $identifier);
     }
     return $result;
 }