PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.0.1
Defender Security – Malware Scanner, Login Security & Firewall v6.0.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 6.0.1, at lib/packages/DI/Definition/Source/DefinitionFile.php

63 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 WPMU_DEV\Defender\Vendor\DI\Definition\Source;
6
7 use WPMU_DEV\Defender\Vendor\DI\Definition\Definition;
8
9 /**
10 * Reads WPMU_DEV\Defender\Vendor\DI definitions from a file returning a PHP array.
11 *
12 * @author Matthieu Napoli <[email protected]>
13 */
14 class DefinitionFile extends DefinitionArray
15 {
16 private bool $initialized = false;
17
18 /**
19 * @param string $file File in which the definitions are returned as an array.
20 */
21 public function __construct(
22 private string $file,
23 ?Autowiring $autowiring = null,
24 ) {
25 // Lazy-loading to improve performances
26 parent::__construct([], $autowiring);
27 }
28
29 public function getDefinition(string $name) : ?Definition
30 {
31 $this->initialize();
32
33 return parent::getDefinition($name);
34 }
35
36 public function getDefinitions() : array
37 {
38 $this->initialize();
39
40 return parent::getDefinitions();
41 }
42
43 /**
44 * Lazy-loading of the definitions.
45 */
46 private function initialize() : void
47 {
48 if ($this->initialized === true) {
49 return;
50 }
51
52 $definitions = require $this->file;
53
54 if (! is_array($definitions)) {
55 throw new \Exception("File $this->file should return an array of definitions");
56 }
57
58 $this->addDefinitions($definitions);
59
60 $this->initialized = true;
61 }
62 }
63