$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 psr($directory) { $directories = static::format($directory); static::$psr = array_unique(array_merge(static::$psr, $directories)); } /** * Map namespaces to directories. * * @param array $mappings * @return void */ public static function namespaces($mappings) { foreach ($mappings as $namespace => $directory) { $namespace = trim($namespace, '\\').'\\'; static::$namespaces[$namespace] = head(static::format($directory)); } } /** * Register underscored "namespaces" to directory mappings. * * @param array $mappings * @return void */ public static function underscored($mappings) { foreach ($mappings as $namespace => $directory) { static::$namespaces[$namespace.'_'] = head(static::format($directory)); } } /** * 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); } }