PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.6.1
Defender Security – Malware Scanner, Login Security & Firewall v5.6.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / DI / Definition / Source / DefinitionFile.php

DefinitionFile.php in Defender Security – Malware Scanner, Login Security & Firewall 5.6.1, at lib/packages/DI/Definition/Source/DefinitionFile.php

70 lines 1.5 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 WPMU_DEV\Defender\Vendor\DI\Definition\Source;
6
7 /**
8 * Reads WPMU_DEV\Defender\Vendor\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