divineniiquaye /
rade-di
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | /* |
||||
| 6 | * This file is part of DivineNii opensource projects. |
||||
| 7 | * |
||||
| 8 | * PHP version 7.4 and above required |
||||
| 9 | * |
||||
| 10 | * @author Divine Niiquaye Ibok <[email protected]> |
||||
| 11 | * @copyright 2021 DivineNii (https://divinenii.com/) |
||||
| 12 | * @license https://opensource.org/licenses/BSD-3-Clause License |
||||
| 13 | * |
||||
| 14 | * For the full copyright and license information, please view the LICENSE |
||||
| 15 | * file that was distributed with this source code. |
||||
| 16 | */ |
||||
| 17 | |||||
| 18 | namespace Rade\DI\Loader; |
||||
| 19 | |||||
| 20 | use Rade\DI\ContainerBuilder; |
||||
| 21 | use Symfony\Component\Config\Resource\FileExistenceResource; |
||||
| 22 | use Symfony\Component\Config\Resource\GlobResource; |
||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * DirectoryLoader is a recursive loader to go through directories. |
||||
| 26 | * |
||||
| 27 | * @author Divine Niiquaye Ibok <[email protected]> |
||||
| 28 | */ |
||||
| 29 | class DirectoryLoader extends FileLoader |
||||
| 30 | { |
||||
| 31 | /** |
||||
| 32 | * {@inheritdoc} |
||||
| 33 | */ |
||||
| 34 | 3 | public function load($file, string $type = null): void |
|||
| 35 | { |
||||
| 36 | 3 | $file = \rtrim($file, '/'); |
|||
| 37 | 3 | $path = $this->locator->locate($file); |
|||
| 38 | |||||
| 39 | 2 | if ($this->container instanceof ContainerBuilder) { |
|||
| 40 | 2 | $this->container->addResource(new FileExistenceResource($file)); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 41 | 2 | $this->container->addResource(new GlobResource($path, '/*', false)); |
|||
|
0 ignored issues
–
show
It seems like
$path can also be of type array; however, parameter $prefix of Symfony\Component\Config...Resource::__construct() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 42 | } |
||||
| 43 | |||||
| 44 | 2 | foreach (\scandir($path) as $dir) { |
|||
|
0 ignored issues
–
show
It seems like
$path can also be of type array; however, parameter $directory of scandir() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 45 | 2 | if ('.' !== $dir[0]) { |
|||
| 46 | 2 | if (\is_dir($path . '/' . $dir)) { |
|||
|
0 ignored issues
–
show
Are you sure
$path of type array|string can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 47 | 1 | $dir .= '/'; // append / to allow recursion |
|||
| 48 | } |
||||
| 49 | |||||
| 50 | 2 | $this->setCurrentDir($path); |
|||
|
0 ignored issues
–
show
It seems like
$path can also be of type array; however, parameter $dir of Symfony\Component\Config...Loader::setCurrentDir() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 51 | 2 | $this->import($dir, null, false, $path); |
|||
|
0 ignored issues
–
show
It seems like
$path can also be of type array; however, parameter $sourceResource of Symfony\Component\Config...er\FileLoader::import() does only seem to accept null|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 52 | } |
||||
| 53 | } |
||||
| 54 | 2 | } |
|||
| 55 | |||||
| 56 | /** |
||||
| 57 | * {@inheritdoc} |
||||
| 58 | */ |
||||
| 59 | 4 | public function supports($resource, string $type = null) |
|||
| 60 | { |
||||
| 61 | 4 | if ('directory' === $type) { |
|||
| 62 | 2 | return true; |
|||
| 63 | } |
||||
| 64 | |||||
| 65 | 4 | return null === $type && \is_string($resource) && '/' === \substr($resource, -1); |
|||
| 66 | } |
||||
| 67 | } |
||||
| 68 |