mirror of
https://github.com/danog/class-finder.git
synced 2024-11-26 20:14:59 +01:00
Add FilesFinder to ClassFinder.
This commit is contained in:
parent
2a7c2dacce
commit
31a4b109ae
@ -4,6 +4,8 @@ namespace HaydenPierce\ClassFinder;
|
||||
use HaydenPierce\ClassFinder\Classmap\ClassmapEntryFactory;
|
||||
use HaydenPierce\ClassFinder\Classmap\ClassmapFinder;
|
||||
use HaydenPierce\ClassFinder\Exception\ClassFinderException;
|
||||
use HaydenPierce\ClassFinder\Files\FilesEntryFactory;
|
||||
use HaydenPierce\ClassFinder\Files\FilesFinder;
|
||||
use HaydenPierce\ClassFinder\PSR4\PSR4Finder;
|
||||
use HaydenPierce\ClassFinder\PSR4\PSR4NamespaceFactory;
|
||||
|
||||
@ -18,6 +20,12 @@ class ClassFinder
|
||||
/** @var ClassmapFinder */
|
||||
private static $classmap;
|
||||
|
||||
/** @var FilesFinder */
|
||||
private static $files;
|
||||
|
||||
/** @var boolean */
|
||||
private static $useFilesSupport;
|
||||
|
||||
private static function initialize()
|
||||
{
|
||||
if (!(self::$config instanceof AppConfig)) {
|
||||
@ -33,6 +41,11 @@ class ClassFinder
|
||||
$classmapFactory = new ClassmapEntryFactory(self::$config);
|
||||
self::$classmap = new ClassmapFinder($classmapFactory);
|
||||
}
|
||||
|
||||
if (!(self::$files instanceof FilesFinder)) {
|
||||
$filesFactory = new FilesEntryFactory(self::$config);
|
||||
self::$files = new FilesFinder($filesFactory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,12 +57,7 @@ class ClassFinder
|
||||
{
|
||||
self::initialize();
|
||||
|
||||
$supportedFinders = array(
|
||||
self::$psr4,
|
||||
self::$classmap
|
||||
);
|
||||
|
||||
$findersWithNamespace = array_filter($supportedFinders, function(FinderInterface $finder) use ($namespace){
|
||||
$findersWithNamespace = array_filter(self::getSupportedFinders(), function(FinderInterface $finder) use ($namespace){
|
||||
return $finder->isNamespaceKnown($namespace);
|
||||
});
|
||||
|
||||
@ -72,4 +80,41 @@ class ClassFinder
|
||||
self::initialize();
|
||||
self::$config->setAppRoot($appRoot);
|
||||
}
|
||||
|
||||
public static function enableFilesSupport()
|
||||
{
|
||||
self::$useFilesSupport = true;
|
||||
}
|
||||
|
||||
public static function disableFilesSupport()
|
||||
{
|
||||
self::$useFilesSupport = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private static function getSupportedFinders()
|
||||
{
|
||||
$supportedFinders = array(
|
||||
self::$psr4,
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user