/** * Register a file into memory and return an instantiated object, based on a dot notated path. * * @access public * @param string $slug * @param array $config * @return object * @static */ public static function factory($slug, array $config = array()) { if (isset(static::$__registered[$slug])) { return static::$__registered[$slug]; } $namespace = App::toNamespace($slug); if (!class_exists($namespace)) { App::import($namespace); } if (class_exists($namespace)) { if (isset(static::$__config[$slug])) { $config = $config + static::$__config[$slug]; } return static::store(new $namespace($config)); } else { throw new Exception(sprintf('Class "%s" could not be instantiated into the registry.', $slug)); } }
/** * Merges the custom configuration with the defaults. Parses the $_classes and imports the class into the scope, * but does not instantiate the object until called. Finally executes construct(). * * @access public * @param array $config * @return void */ public function __construct(array $config = array()) { if (!empty($config)) { $this->_config = $config + $this->_config; } if (!empty($this->_classes)) { foreach ($this->_classes as $class => $options) { if (isset($options['namespace'])) { App::import($namespace); } } } $this->construct(); }