/** * Creates a new instance of an $alias class. * * @param string $alias * @return mixed * @throws \Exception If the given class is not found */ public static function factory($alias, $arg = null) { $args = is_null($arg) ? null : array_slice(func_get_args(), 1); // Load it if (isset(static::$registry[$alias]['callback'])) { return call_user_func_array(static::$registry[$alias]['callback'], (array) $args); } // Check for configuration arguments and configuration file if (is_null($args)) { $args = static::findConfig($alias); } // Auto-create it try { return DI::reflect($alias, $args); } catch (\ReflectionException $e) { // echo $e; } if (isset(static::$registry[$alias]['alias'])) { return static::factory(static::$registry[$alias]['alias'], $args); } // Check for \Sugi\$alias if (strpos($alias, '\\') === false) { return DI::reflect("\\Sugi\\{$alias}", $args); } throw new \Exception("Could not find {$alias} class"); }