1- <?php namespace Winter \Storm \Config ;
1+ <?php namespace Winter \Storm \Parse \ PHP ;
22
33use PhpParser \Error ;
44use PhpParser \Node \Expr \Array_ ;
@@ -24,43 +24,41 @@ class ArrayFile implements FileInterface
2424 * @var Stmt[]|null Abstract syntax tree produced by `PhpParser`
2525 */
2626 protected $ ast = null ;
27+
2728 /**
28- * @var string|null Source config file
29+ * @var string|null Path to the file
2930 */
30- protected $ file = null ;
31+ protected $ filePath = null ;
32+
3133 /**
32- * @var PrettyPrinterAbstract|WinterPrinter |null Printer used to define output syntax
34+ * @var PrettyPrinterAbstract|ArrayPrinter |null Printer used to define output syntax
3335 */
3436 protected $ printer = null ;
3537
3638 /**
37- * ConfigFile constructor.
38- *
39- * @param Stmt[]|null $ast
40- * @param string $file
41- * @param PrettyPrinterAbstract|null $printer
39+ * ArrayFile constructor.
4240 */
43- public function __construct (array $ ast , string $ file = null , PrettyPrinterAbstract $ printer = null )
41+ public function __construct (array $ ast , string $ filePath = null , PrettyPrinterAbstract $ printer = null )
4442 {
4543 if (!($ ast [0 ] instanceof Stmt \Return_)) {
46- throw new \InvalidArgumentException ('configs must start with a return statement ' );
44+ throw new \InvalidArgumentException ('ArrayFiles must start with a return statement ' );
4745 }
4846
4947 $ this ->ast = $ ast ;
50- $ this ->file = $ file ;
51- $ this ->printer = $ printer ?? new WinterPrinter ();
48+ $ this ->filePath = $ filePath ;
49+ $ this ->printer = $ printer ?? new ArrayPrinter ();
5250 }
5351
5452 /**
55- * Return a new instance of `ConfigFile ` ready for modification of the file.
53+ * Return a new instance of `ArrayFile ` ready for modification of the file.
5654 *
57- * @param string $file
55+ * @param string $filePath
5856 * @param bool $createMissing
59- * @return ConfigFile |null
57+ * @return ArrayFile |null
6058 */
61- public static function read (string $ file , bool $ createMissing = false ): ?ConfigFile
59+ public static function read (string $ filePath , bool $ createMissing = false ): ?ArrayFile
6260 {
63- $ exists = file_exists ($ file );
61+ $ exists = file_exists ($ filePath );
6462
6563 if (!$ exists && !$ createMissing ) {
6664 throw new \InvalidArgumentException ('file not found ' );
@@ -71,14 +69,14 @@ public static function read(string $file, bool $createMissing = false): ?ConfigF
7169 try {
7270 $ ast = $ parser ->parse (
7371 $ exists
74- ? file_get_contents ($ file )
72+ ? file_get_contents ($ filePath )
7573 : sprintf ('<?php%1$s%1$sreturn [];%1$s ' , "\n" )
7674 );
7775 } catch (Error $ e ) {
7876 throw new SystemException ($ e );
7977 }
8078
81- return new static ($ ast , $ file );
79+ return new static ($ ast , $ filePath );
8280 }
8381
8482 /**
@@ -97,7 +95,7 @@ public static function read(string $file, bool $createMissing = false): ?ConfigF
9795 * @param mixed|null $value
9896 * @return $this
9997 */
100- public function set ($ key , $ value = null ): ConfigFile
98+ public function set ($ key , $ value = null ): ArrayFile
10199 {
102100 if (is_array ($ key )) {
103101 foreach ($ key as $ name => $ value ) {
@@ -237,11 +235,11 @@ protected function castArray(array $array): Array_
237235 */
238236 protected function getType ($ var ): string
239237 {
240- if ($ var instanceof ConfigFunction ) {
238+ if ($ var instanceof PHPFunction ) {
241239 return 'function ' ;
242240 }
243241
244- if ($ var instanceof ConfigConst ) {
242+ if ($ var instanceof PHPConst ) {
245243 return 'const ' ;
246244 }
247245
@@ -318,12 +316,11 @@ protected function seek(array $path, &$pointer, int $depth = 0): array
318316 }
319317
320318 /**
321- * Sort the config, supports: ConfigFile ::SORT_ASC, ConfigFile ::SORT_DESC, callable
319+ * Sort the config, supports: ArrayFile ::SORT_ASC, ArrayFile ::SORT_DESC, callable
322320 *
323321 * @param string|callable $mode
324- * @return ConfigFile
325322 */
326- public function sort ($ mode = self ::SORT_ASC ): ConfigFile
323+ public function sort ($ mode = self ::SORT_ASC ): ArrayFile
327324 {
328325 if (is_callable ($ mode )) {
329326 usort ($ this ->ast [0 ]->expr ->items , $ mode );
@@ -372,34 +369,34 @@ protected function sortRecursive(array &$array, string $mode): void
372369 */
373370 public function write (string $ filePath = null ): void
374371 {
375- if (!$ filePath && $ this ->file ) {
376- $ filePath = $ this ->file ;
372+ if (!$ filePath && $ this ->filePath ) {
373+ $ filePath = $ this ->filePath ;
377374 }
378375
379376 file_put_contents ($ filePath , $ this ->render ());
380377 }
381378
382379 /**
383- * Returns a new instance of ConfigFunction
380+ * Returns a new instance of PHPFunction
384381 *
385382 * @param string $name
386383 * @param array $args
387- * @return ConfigFunction
384+ * @return PHPFunction
388385 */
389- public function function (string $ name , array $ args ): ConfigFunction
386+ public function function (string $ name , array $ args ): PHPFunction
390387 {
391- return new ConfigFunction ($ name , $ args );
388+ return new PHPFunction ($ name , $ args );
392389 }
393390
394391 /**
395- * Returns a new instance of ConfigConst
392+ * Returns a new instance of PHPConst
396393 *
397394 * @param string $name
398- * @return ConfigConst
395+ * @return PHPConst
399396 */
400- public function const (string $ name ): ConfigConst
397+ public function const (string $ name ): PHPConst
401398 {
402- return new ConfigConst ($ name );
399+ return new PHPConst ($ name );
403400 }
404401
405402 /**
0 commit comments