findClasses($namespace, $options)); }, array()); return array_unique($classes); } /** * Check if a given namespace contains any classes. * * @param string $namespace * @return bool */ public static function namespaceHasClasses($namespace) { self::initialize(); return count(self::findersWithNamespace($namespace)) > 0; } /** * @param string $appRoot * @return void */ public static function setAppRoot($appRoot) { self::initialize(); self::$config->setAppRoot($appRoot); } /** * @return void */ public static function enableExperimentalFilesSupport() { self::$useFilesSupport = true; } /** * @return void */ public static function disableExperimentalFilesSupport() { self::$useFilesSupport = false; } /** * @return void */ public static function enablePSR4Support() { self::$usePSR4Support = true; } /** * @return void */ public static function disablePSR4Support() { self::$usePSR4Support = false; } /** * @return void */ public static function enableClassmapSupport() { self::$useClassmapSupport = true; } /** * @return void */ public static function disableClassmapSupport() { self::$useClassmapSupport = false; } /** * @return FinderInterface[] */ private static function getSupportedFinders() { $supportedFinders = array(); /* * This is done for testing. For some tests, allowing PSR4 classes contaminates the test results. This could also be * disabled for performance reasons (less finders in use means less work), but most people probably won't do that. */ if (self::$usePSR4Support) { $supportedFinders[] = self::$psr4; } /* * This is done for testing. For some tests, allowing classmap classes contaminates the test results. This could also be * disabled for performance reasons (less finders in use means less work), but most people probably won't do that. */ if (self::$useClassmapSupport) { $supportedFinders[] = self::$classmap; } /* * Files support is tucked away behind a flag because it will need to use some kind of shell access via exec, or * system. * * #1 Many environments (such as shared space hosts) may not allow these functions, and attempting to call * these functions will blow up. * #2 I've heard of performance issues with calling these functions. * #3 Files support probably doesn't benefit most projects. * #4 Using exec() or system() is against many PHP developers' religions. */ if (self::$useFilesSupport) { $supportedFinders[] = self::$files; } return $supportedFinders; } /** * @param string $namespace * @return FinderInterface[] */ private static function findersWithNamespace($namespace) { $findersWithNamespace = array_filter(self::getSupportedFinders(), function (FinderInterface $finder) use ($namespace) { return $finder->isNamespaceKnown($namespace); }); return $findersWithNamespace; } }