1111
1212namespace Doctum ;
1313
14+ use ArrayAccess ;
1415use PhpParser \NodeTraverser ;
1516use PhpParser \NodeVisitor \NameResolver ;
1617use PhpParser \ParserFactory ;
3637use Wdes \phpI18nL10n \plugins \MoReader ;
3738use Wdes \phpI18nL10n \Launcher ;
3839
39- class Doctum
40+ class Doctum implements ArrayAccess
4041{
4142 public const VERSION_MAJOR = 5 ;
4243 public const VERSION_MINOR = 2 ;
@@ -47,16 +48,20 @@ class Doctum
4748 public const VERSION = self ::VERSION_MAJOR . '. ' . self ::VERSION_MINOR . '. ' . self ::VERSION_PATCH . (self ::IS_DEV ? '-dev ' : '' );
4849
4950 public static $ defaultVersionName = 'main ' ;
51+ /**
52+ * @var \Symfony\Component\Finder\Finder
53+ */
54+ private $ files ;
5055
5156 public function __construct ($ iterator = null , array $ config = [])
5257 {
5358 $ sc = $ this ;
5459
5560 if (null !== $ iterator ) {
56- $ this [ ' files ' ] = $ iterator ;
61+ $ this -> files = $ iterator ;
5762 }
5863
59- $ this ['_versions ' ] = function ($ sc ) {
64+ $ this ['_versions ' ] = function () use ( $ sc ) {
6065 $ versions = $ sc ['versions ' ] ?? $ sc ['version ' ];
6166
6267 if (is_string ($ versions )) {
@@ -70,7 +75,7 @@ public function __construct($iterator = null, array $config = [])
7075 return $ versions ;
7176 };
7277
73- $ this ['project ' ] = function ($ sc ) {
78+ $ this ['project ' ] = function () use ( $ sc ) {
7479 $ project = new Project ($ sc ['store ' ], $ sc ['_versions ' ], [
7580 'build_dir ' => $ sc ['build_dir ' ],
7681 'cache_dir ' => $ sc ['cache_dir ' ],
@@ -94,8 +99,8 @@ public function __construct($iterator = null, array $config = [])
9499 return $ project ;
95100 };
96101
97- $ this ['parser ' ] = function ($ sc ) {
98- return new Parser ($ sc[ ' files ' ] , $ sc ['store ' ], $ sc ['code_parser ' ], $ sc ['traverser ' ]);
102+ $ this ['parser ' ] = function () use ( $ sc ) {
103+ return new Parser ($ sc-> files , $ sc ['store ' ], $ sc ['code_parser ' ], $ sc ['traverser ' ]);
99104 };
100105
101106 $ this ['indexer ' ] = function () {
@@ -106,7 +111,7 @@ public function __construct($iterator = null, array $config = [])
106111 return new Tree ();
107112 };
108113
109- $ this ['parser_context ' ] = function ($ sc ) {
114+ $ this ['parser_context ' ] = function () use ( $ sc ) {
110115 return new ParserContext ($ sc ['filter ' ], $ sc ['docblock_parser ' ], $ sc ['pretty_printer ' ]);
111116 };
112117
@@ -118,15 +123,15 @@ public function __construct($iterator = null, array $config = [])
118123 return (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 );
119124 };
120125
121- $ this ['php_traverser ' ] = function ($ sc ) {
126+ $ this ['php_traverser ' ] = function () use ( $ sc ) {
122127 $ traverser = new NodeTraverser ();
123128 $ traverser ->addVisitor (new NameResolver ());
124129 $ traverser ->addVisitor (new NodeVisitor ($ sc ['parser_context ' ]));
125130
126131 return $ traverser ;
127132 };
128133
129- $ this ['code_parser ' ] = function ($ sc ) {
134+ $ this ['code_parser ' ] = function () use ( $ sc ) {
130135 return new CodeParser ($ sc ['parser_context ' ], $ sc ['php_parser ' ], $ sc ['php_traverser ' ]);
131136 };
132137
@@ -142,11 +147,11 @@ public function __construct($iterator = null, array $config = [])
142147 return new JsonStore ();
143148 };
144149
145- $ this ['renderer ' ] = function ($ sc ) {
150+ $ this ['renderer ' ] = function () use ( $ sc ) {
146151 return new Renderer ($ sc ['twig ' ], $ sc ['themes ' ], $ sc ['tree ' ], $ sc ['indexer ' ]);
147152 };
148153
149- $ this ['traverser ' ] = function ($ sc ) {
154+ $ this ['traverser ' ] = function () use ( $ sc ) {
150155 $ visitors = [
151156 new ClassVisitor \InheritdocClassVisitor (),
152157 new ClassVisitor \MethodClassVisitor (),
@@ -160,7 +165,7 @@ public function __construct($iterator = null, array $config = [])
160165 return new ClassTraverser ($ visitors );
161166 };
162167
163- $ this ['themes ' ] = function ($ sc ) {
168+ $ this ['themes ' ] = function () use ( $ sc ) {
164169 $ templates = $ sc ['template_dirs ' ];
165170 $ templates [] = __DIR__ . '/Resources/themes ' ;
166171
@@ -207,7 +212,7 @@ public function __construct($iterator = null, array $config = [])
207212 $ this ['include_parent_data ' ] = true ;
208213
209214 foreach ($ config as $ key => $ value ) {
210- $ this [ $ key] = $ value ;
215+ $ this ->{ $ key} = $ value ;
211216 }
212217 }
213218
@@ -220,4 +225,22 @@ public function getProject(): Project
220225 {
221226 return $ this ['project ' ];
222227 }
228+
229+ public function offsetSet ($ offset , $ value ) {
230+ if (is_callable ($ this ->{$ offset })) {
231+ $ this ->{$ offset } = $ this ->{$ offset }();
232+ }
233+ }
234+
235+ public function offsetExists ($ offset ) {
236+ return isset ($ this ->{$ offset });
237+ }
238+
239+ public function offsetUnset ($ offset ) {
240+ unset($ this ->{$ offset });
241+ }
242+
243+ public function offsetGet ($ offset ) {
244+ return isset ($ this ->{$ offset }) ? $ this ->{$ offset } : null ;
245+ }
223246}
0 commit comments