$directory) { if (starts_with($class, $namespace)) { return compact('namespace', 'directory'); } } } /** * Register an array of class to path mappings. * * @param array $mappings * @return void */ public static function map($mappings) { static::$mappings = array_merge(static::$mappings, $mappings); } /** * Register a class alias with the auto-loader. * * @param string $class * @param string $alias * @return void */ public static function alias($class, $alias) { static::$aliases[$alias] = $class; } /** * Register directories to be searched as a PSR-0 library. * * @param string|array $directory * @return void */ public static function directories($directory) { $directories = static::format($directory); static::$directories = array_unique(array_merge(static::$directories, $directories)); } /** * Register underscored "namespaces" to directory mappings. * * @param array $mappings * @return void */ public static function underscored($mappings) { static::namespaces($mappings, '_'); } /** * Map namespaces to directories. * * @param array $mappings * @param string $append * @return void */ public static function namespaces($mappings, $append = '\\') { foreach ($mappings as $namespace => $directory) { // When adding new namespaces to the mappings, we will unset the previously // mapped value if it existed. This allows previously registered spaces to // be mapped to new directories on the fly. $namespace = trim($namespace, $append).$append; unset(static::$namespaces[$namespace]); $namespaces[$namespace] = head(static::format($directory)); } // We'll array_merge the new mappings onto the front of the array so // derivative namespaces are not always shadowed by their parents. // For instance, when mappings Laravel\Docs, we don't want the // main Laravel namespace to always override it. static::$namespaces = array_merge($namespaces, static::$namespaces); } /** * Format an array of directories with the proper trailing slashes. * * @param array $directories * @return array */ protected static function format($directories) { return array_map(function($directory) { return rtrim($directory, DS).DS; }, (array) $directories); } }