PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.0
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Dependencies / DI / Definition / Source / DefinitionFile.php

DefinitionFile.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.5.0, at includes/Dependencies/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 WPDeveloper\BetterDocs\Dependencies\DI\Definition\Source;
6
7 /**
8 * Reads WPDeveloper\BetterDocs\Dependencies\DI definitions from a file returning a PHP array.
9 *
10 * @author Matthieu Napoli <matthieu@mnapoli.fr>
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