Issues (23)

src/DefinitionLoader/FileDefinitionLoader.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\DefinitionLoader;
11
12
use ArrayObject;
13
use Slick\Di\Definition\CreateDefinitionsMethods;
14
use Slick\Di\Definition\ObjectDefinition;
15
use Slick\Di\DefinitionLoaderInterface;
16
use Traversable;
17
18
/**
19
 * FileDefinitionLoader
20
 *
21
 * @package Slick\Di\DefinitionLoader
22
 * @author  Filipe Silva <[email protected]>
23
*/
24
class FileDefinitionLoader implements DefinitionLoaderInterface
25
{
26
    use CreateDefinitionsMethods;
27
28
    private array $definitions = [];
29
30
    public function __construct(string|array $definitions)
31
    {
32
        $services = is_string($definitions) ? require $definitions : $definitions;
0 ignored issues
show
The condition is_string($definitions) is always false.
Loading history...
33
        foreach ($services as $name => $definition) {
34
            $this->definitions[$name] = $definition instanceof ObjectDefinition
35
                ? $definition
36
                : $this->createDefinition($definition);
37
        }
38
    }
39
40
41
    public function getIterator(): Traversable
42
    {
43
        return new ArrayObject($this->definitions);
44
    }
45
}
46