1
0
mirror of https://github.com/danog/class-finder.git synced 2025-01-23 06:11:26 +01:00

Bootstrap files finder and supporting classes.

This commit is contained in:
Hayden Pierce 2018-09-29 13:00:26 -05:00
parent 8a653d80ba
commit f56e0b26d4
3 changed files with 98 additions and 0 deletions

26
src/Files/FilesEntry.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace HaydenPierce\ClassFinder\Files;
class FilesEntry
{
private $file;
public function __construct($fileToInclude)
{
$this->file = $fileToInclude;
}
public function knowsNamespace($namespace)
{
// TODO.
}
/**
* @param $namespace
* @return bool
*/
public function matches($namespace)
{
// TODO.
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace HaydenPierce\ClassFinder\Files;
use HaydenPierce\ClassFinder\AppConfig;
class FilesEntryFactory
{
/** @var AppConfig */
private $appConfig;
public function __construct(AppConfig $appConfig)
{
$this->appConfig = $appConfig;
}
/**
* @return array
*/
public function getFilesEntries()
{
$files = array();
$filesKeys = array_keys($files);
return array_map(function($index) use ($filesKeys){
return new FilesEntry($filesKeys[$index]);
}, range(0, count($files) - 1));
}
}

44
src/Files/FilesFinder.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace HaydenPierce\ClassFinder\Files;
use HaydenPierce\ClassFinder\FinderInterface;
class FilesFinder implements FinderInterface
{
private $factory;
public function __construct(FilesEntryFactory $factory)
{
$this->factory = $factory;
}
public function isNamespaceKnown($namespace)
{
$filesEntries = $this->factory->getfilesEntries();
foreach($filesEntries as $filesEntry) {
if ($filesEntry->knowsNamespace($namespace)) {
return true;
}
}
return false;
}
/**
* @param $namespace
* @return bool|string
*/
public function findClasses($namespace)
{
$filesEntries = $this->factory->getFilesEntries();
$matchingEntries = array_filter($filesEntries, function(filesEntry $entry) use ($namespace) {
return $entry->matches($namespace);
});
return array_map(function(filesEntry $entry) {
return $entry->getClassName();
}, $matchingEntries);
}
}