PluginProbe
The Innovative Form Builder – IvyForms / 0.1.2
The Innovative Form Builder – IvyForms v0.1.2
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / vendor / php-di / php-di / src / Definition / Source / DefinitionFile.php

DefinitionFile.php in The Innovative Form Builder – IvyForms 0.1.2, at backend/vendor/php-di/php-di/src/Definition/Source/DefinitionFile.php

70 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace DI\Definition\Source;
6
7 /**
8 * Reads DI definitions from a file returning a PHP array.
9 *
10 * @author Matthieu Napoli <[email protected]>
11 */
12 class DefinitionFile extends DefinitionArray
13 {
14 /**
15 * @var bool
16 */
17 private $initialized = false;
18
19 /**
20 * File containing definitions, or null if the definitions are given as a PHP array.
21 * @var string|null
22 */
23 private $file;
24
25 /**
26 * @param string $file File in which the definitions are returned as an array.
27 */
28 public function __construct($file, Autowiring $autowiring = null)
29 {
30 // Lazy-loading to improve performances
31 $this->file = $file;
32
33 parent::__construct([], $autowiring);
34 }
35
36 public function getDefinition(string $name)
37 {
38 $this->initialize();
39
40 return parent::getDefinition($name);
41 }
42
43 public function getDefinitions() : array
44 {
45 $this->initialize();
46
47 return parent::getDefinitions();
48 }
49
50 /**
51 * Lazy-loading of the definitions.
52 */
53 private function initialize()
54 {
55 if ($this->initialized === true) {
56 return;
57 }
58
59 $definitions = require $this->file;
60
61 if (! is_array($definitions)) {
62 throw new \Exception("File {$this->file} should return an array of definitions");
63 }
64
65 $this->addDefinitions($definitions);
66
67 $this->initialized = true;
68 }
69 }
70