-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-arrange files and fixed code complexity
- Loading branch information
1 parent
89129eb
commit f681ad5
Showing
39 changed files
with
1,575 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This code is under BSD 3-Clause "New" or "Revised" License. | ||
* | ||
* PHP version 7 and above required | ||
* | ||
* @category LoaderManager | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
* @copyright 2019 Biurad Group (https://biurad.com/) | ||
* @license https://opensource.org/licenses/BSD-3-Clause License | ||
* | ||
* @link https://www.biurad.com/projects/biurad-loader | ||
* @since Version 0.1 | ||
*/ | ||
|
||
namespace BiuradPHP\Loader; | ||
|
||
use BiuradPHP\Loader\Interfaces\AliasTypeInterface; | ||
use BiuradPHP\Loader\Interfaces\LoaderInterface; | ||
|
||
/** | ||
* AliasLoader loads namesapces and class aliases from ConfigLocator. | ||
* | ||
* @author Divine Niiquaye <divineibok@gmail.com> | ||
* @license BSD-3-Cluase | ||
*/ | ||
class AliasLoader implements LoaderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return array|AliasTypeInterface | ||
*/ | ||
public function load($resource, string $type = null) | ||
{ | ||
return $resource; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($resource, string $type = null): bool | ||
{ | ||
if ('alias' === $type && is_array($resource)) { | ||
return true; | ||
} | ||
|
||
return $resource instanceof AliasTypeInterface; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This code is under BSD 3-Clause "New" or "Revised" License. | ||
* | ||
* PHP version 7 and above required | ||
* | ||
* @category LoaderManager | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
* @copyright 2019 Biurad Group (https://biurad.com/) | ||
* @license https://opensource.org/licenses/BSD-3-Clause License | ||
* | ||
* @link https://www.biurad.com/projects/biurad-loader | ||
* @since Version 0.1 | ||
*/ | ||
|
||
namespace BiuradPHP\Loader\Bridges; | ||
|
||
use BiuradPHP\DependencyInjection\Concerns\ContainerBuilder; | ||
use BiuradPHP\DependencyInjection\Interfaces\CompilerPassInterface; | ||
use BiuradPHP\Loader\DelegatingLoader; | ||
use BiuradPHP\Loader\Interfaces\LoaderInterface; | ||
|
||
class LoaderPassCompiler implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$loader = $container->getDefinitionByType(DelegatingLoader::class); | ||
|
||
foreach ($container->findByType(LoaderInterface::class) as $name => $definition) { | ||
$newStatement = $definition->getFactory(); | ||
$container->removeDefinition($name); | ||
|
||
$loader->addSetup('addLoader', [$newStatement]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This code is under BSD 3-Clause "New" or "Revised" License. | ||
* | ||
* PHP version 7 and above required | ||
* | ||
* @category LoaderManager | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
* @copyright 2019 Biurad Group (https://biurad.com/) | ||
* @license https://opensource.org/licenses/BSD-3-Clause License | ||
* | ||
* @link https://www.biurad.com/projects/biurad-loader | ||
* @since Version 0.1 | ||
*/ | ||
|
||
namespace BiuradPHP\Loader; | ||
|
||
use BiuradPHP\Loader\Interfaces\LoaderInterface; | ||
use BiuradPHP\Loader\Locators\ConfigLocator; | ||
|
||
/** | ||
* ConfigFileLoader loads files from ConfigLocator. | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
*/ | ||
class ConfigFileLoader implements LoaderInterface | ||
{ | ||
private $loader; | ||
|
||
/** | ||
* @param ConfigLocator $Locator | ||
*/ | ||
public function __construct(ConfigLocator $Locator = null) | ||
{ | ||
$this->loader = $Locator ?: new ConfigLocator(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return array | ||
*/ | ||
public function load($resource, string $type = null): array | ||
{ | ||
return $this->loader->loadFile($resource); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($resource, string $type = null): bool | ||
{ | ||
return 'config' === $type && (file_exists($resource) && is_file($resource)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This code is under BSD 3-Clause "New" or "Revised" License. | ||
* | ||
* PHP version 7 and above required | ||
* | ||
* @category LoaderManager | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
* @copyright 2019 Biurad Group (https://biurad.com/) | ||
* @license https://opensource.org/licenses/BSD-3-Clause License | ||
* | ||
* @link https://www.biurad.com/projects/biurad-loader | ||
* @since Version 0.1 | ||
*/ | ||
|
||
namespace BiuradPHP\Loader; | ||
|
||
use BiuradPHP\Loader\Interfaces\LoaderInterface; | ||
|
||
/** | ||
* DelegatingLoader delegates loading to other loaders using a loader resolver. | ||
* | ||
* This loader acts as an array of LoaderInterface objects - each having | ||
* a chance to load a given resource. | ||
* | ||
* @author Divine Niiquaye Ibok <divineibok@gmail.com> | ||
*/ | ||
class DelegatingLoader implements LoaderInterface | ||
{ | ||
/** | ||
* @var LoaderInterface[] An array of LoaderInterface objects | ||
*/ | ||
private $loaders = []; | ||
|
||
/** | ||
* @param LoaderInterface[] $loaders An array of loaders | ||
*/ | ||
public function __construct(array $loaders = []) | ||
{ | ||
foreach ($loaders as $loader) { | ||
$this->addLoader($loader); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load($resource, string $type = null) | ||
{ | ||
foreach ($this->loaders as $loader) { | ||
if ($loader->supports($resource, $type)) { | ||
return $loader->load($resource, $type); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($resource, string $type = null): bool | ||
{ | ||
return false !== $this->load($resource, $type); | ||
} | ||
|
||
/** | ||
* Add a LoaderInterface instance to $this class. | ||
* | ||
* @param LoaderInterface $loader | ||
* @return void | ||
*/ | ||
public function addLoader(LoaderInterface $loader): void | ||
{ | ||
$this->loaders[] = $loader; | ||
} | ||
} |
Oops, something went wrong.