nstanceof KObjectIdentifier) { $identifier->getDecorators()->append(array($decorator)); } else { $identifier->getDecorators()->append(array($decorator => $config)); } //If the identifier already exists decorate it if ($this->isRegistered($identifier)) { $delegate = $this->__registry->get($identifier); $this->_decorate($identifier, $delegate); } return $this; } /** * Register an object locator * * @param mixed $identifier An KObjectIdentifier, identifier string or object implementing KObjectLocatorInterface * @param array $config * @throws UnexpectedValueException * @return KObjectManager */ public function registerLocator($identifier, array $config = array()) { if(!$identifier instanceof KObjectLocatorInterface) { $locator = $this->getObject($identifier, $config); if(!$locator instanceof KObjectLocatorInterface) { throw new UnexpectedValueException( 'Locator: '.get_class($locator).' does not implement KObjectLocatorInterface' ); } } else $locator = $identifier; //Add the locator $this->_locators[$locator->getName()] = $locator; return $this; } /** * Get a registered object locator based on his type * * @param string $type The locator type * @return KObjectLocatorInterface|null Returns the object locator or NULL if it cannot be found. */ public function getLocator($type) { $result = null; if(isset($this->_locators[$type])) { $result = $this->_locators[$type]; } return $result; } /** * Get the registered class locators * * @return array */ public function getLocators() { return $this->_locators; } /** * Set an alias for an identifier * * @param mixed $identifier An KObjectIdentifier, identifier string or object implementing KObjectInterface * @param string $alias The identifier alias * @return KObjectManager * @throws KObjectExceptionInvalidIdentifier If the identifier is not valid */ public function registerAlias($identifier, $alias) { $identifier = $this->getIdentifier($identifier); $alias = $this->getIdentifier($alias); //Register the alias for the identifier $this->__registry->alias($identifier, (string) $alias); //Merge alias configuration into the identifier $identifier->getConfig()->append($alias->getConfig()); // Register alias mixins. foreach ($alias->getMixins() as $mixin) { $this->registerMixin($identifier, $mixin); } return $this; } /** * Get the aliases for an identifier * * @param mixed $identifier An KObjectIdentifier, identifier string or object implementing KObjectInterface * @return array An array of aliases * @throws KObjectExceptionInvalidIdentifier If the identifier is not valid */ public function getAliases($identifier) { return array_search((string) $identifier, $this->__registry->getAliases()); } /** * Get the class loader * * @return KClassLoaderInterface */ public function getClassLoader() { return $this->__loader; } /** * Set the class loader * * @param KClassLoaderInterface $loader * @return KObjectManagerInterface */ public function setClassLoader(KClassLoaderInterface $loader) { $this->__loader = $loader; return $this; } /** * Check if the object instance exists based on the identifier * * @param mixed $identifier An KObjectIdentifier, identifier string or object implementing KObjectInterface * @return KObjectInterface|false Returns the registered object on success or FALSE on failure. * @throws KObjectExceptionInvalidIdentifier If the identifier is not valid */ public function isRegistered($identifier) { $result = false; try { $registered = $this->getIdentifier($identifier); //Get alias for singletons if($registered->getType() != 'lib' && $this->isSingleton($registered)) { $parts = $registered->toArray(); unset($parts['type']); unset($parts['domain']); unset($parts['package']); //Create singleton identifier : path.name $registered = $this->getIdentifier($parts); } $object = $this->__registry->get($registered); //If the object implements ObjectInterface we have registered an object if($object instanceof KObjectInterface) { $result = $object; } } catch (KObjectExceptionInvalidIdentifier $e) {} return $result; } /** * Check if the object is a multiton * * @param mixed $identifier An object that implements the ObjectInterface, an ObjectIdentifier or valid identifier string * @return boolean Returns TRUE if the object is a singleton, FALSE otherwise. */ public function isMultiton($identifier) { $result = false; $class = $this->getClass($identifier); if($class) { $result = array_key_exists('KObjectMultiton', class_implements($class)); } return $result; } /** * Check if the object is a singleton * * @param mixed $identifier An object that implements the ObjectInterface, an ObjectIdentifier or valid identifier string * @return boolean Returns TRUE if the object is a singleton, FALSE otherwise. */ public function isSingleton($identifier) { $result = false; $class = $this->getClass($identifier); if($class) { $result = array_key_exists('KObjectSingleton', class_implements($class)); } return $result; } /** * Perform the actual mixin of all registered mixins for an object * * @param KObjectIdentifier $identifier * @param KObjectMixable $mixer * @return KObjectMixable The mixed object */ protected function _mixin(KObjectIdentifier $identifier, $mixer) { if ($mixer instanceof KObjectMixable) { $mixins = $identifier->getMixins(); foreach ($mixins as $key => $value) { if (is_numeric($key)) { $mixer->mixin($value); } else { $mixer->mixin($key, $value); } } } return $mixer; } /** * Perform the actual decoration of all registered decorators for an object * * @param KObjectIdentifier $identifier * @param KObjectDecoratable $delegate * @return KObjectDecorator The decorated object */ protected function _decorate(KObjectIdentifier $identifier, $delegate) { if ($delegate instanceof KObjectDecoratable) { $decorators = $identifier->getDecorators(); foreach ($decorators as $key => $value) { if (is_numeric($key)) { $delegate = $delegate->decorate($value); } else { $delegate = $delegate->decorate($key, $value); } } } return $delegate; } /** * Configure an identifier * * @param KObjectIdentifier $identifier * @param array $data * @return KObjectConfig */ protected function _configure(KObjectIdentifier $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; } /** * Get an instance of a class based on a class identifier * * @param KObjectIdentifier $identifier * @param bool $fallback Use fallbacks when locating the class. Default is TRUE. * @return string Return the identifier class or FALSE on failure. */ protected function _locate(KObjectIdentifier $identifier, $fallback = true) { $class = $this->__registry->getClass($identifier); //If the class is FALSE we have tried to locate it already, do not locate it again. if($class !== false) { //Set loader basepath if we are locating inside an application if($this->isRegistered('object.bootstrapper')) { if($path = $this->getObject('object.bootstrapper')->getApplicationPath($identifier->domain)) { $this->getClassLoader()->setBasePath($path); } } if(empty($class)) { $class = $this->_locators[$identifier->getType()]->locate($identifier, $fallback); //If we are falling back set the class in the registry if($fallback) { if(!$this->__registry->get($identifier) instanceof KObjectInterface) { $this->__registry->setClass($identifier, $class); } } } } return $class; } /** * Get an instance of a class based on a class identifier * * @param KObjectIdentifier $identifier * @param array $config An optional associative array of configuration settings. * @return object Return object on success, throws exception on failure * @throws KObjectExceptionInvalidObject If the object doesn't implement the KObjectInterface * @throws KObjectExceptionNotFound If object cannot be loaded * @throws KObjectExceptionNotInstantiated If object cannot be instantiated */ protected function _instantiate(KObjectIdentifier $identifier, array $config = array()) { $result = null; //Get the class name and set it in the identifier $class = $this->getClass($identifier); if($class && class_exists($class)) { if (!array_key_exists('KObjectInterface', class_implements($class, false))) { throw new KObjectExceptionInvalidObject( 'Object: '.$class.' does not implement KObjectInterface' ); } //Configure the identifier $config = $this->_configure($identifier, $config); // Delegate object instantiation. if (array_key_exists('KObjectInstantiable', class_implements($class, false))) { $result = call_user_func(array($class, 'getInstance'), $config, $this); } else { $result = new $class($config); } //Thrown an error if no object was instantiated if (!is_object($result)) { throw new KObjectExceptionNotInstantiated( 'Cannot instantiate object from identifier: ' . $class ); } } else throw new KObjectExceptionNotFound('Cannot load object from identifier: '. $identifier); return $result; } } 500 Internal Server Error
Failed to load 'rt_gemini' template: Please install Gantry 5 Framework!