@@ -19,34 +19,34 @@ discard block |
||
19 | 19 | */ |
20 | 20 | |
21 | 21 | class FlattedString { |
22 | - public $value = ''; |
|
23 | - public function __construct($value) { |
|
22 | + public $value = ''; |
|
23 | + public function __construct($value) { |
|
24 | 24 | $this->value = $value; |
25 | - } |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class Flatted { |
29 | 29 | |
30 | - // public utilities |
|
31 | - public static function parse($json, $assoc = false, $depth = 512, $options = 0) { |
|
30 | + // public utilities |
|
31 | + public static function parse($json, $assoc = false, $depth = 512, $options = 0) { |
|
32 | 32 | $input = array_map( |
33 | - 'Flatted::asString', |
|
34 | - array_map( |
|
33 | + 'Flatted::asString', |
|
34 | + array_map( |
|
35 | 35 | 'Flatted::wrap', |
36 | 36 | json_decode($json, $assoc, $depth, $options) |
37 | - ) |
|
37 | + ) |
|
38 | 38 | ); |
39 | 39 | $value = &$input[0]; |
40 | 40 | $set = array(); |
41 | 41 | $set[] = &$value; |
42 | 42 | if (is_array($value)) |
43 | - return Flatted::loop(false, array_keys($value), $input, $set, $value); |
|
43 | + return Flatted::loop(false, array_keys($value), $input, $set, $value); |
|
44 | 44 | if (is_object($value)) |
45 | - return Flatted::loop(true, Flatted::keys($value), $input, $set, $value); |
|
45 | + return Flatted::loop(true, Flatted::keys($value), $input, $set, $value); |
|
46 | 46 | return $value; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public static function stringify($value, $options = 0, $depth = 512) { |
|
49 | + public static function stringify($value, $options = 0, $depth = 512) { |
|
50 | 50 | $known = new stdClass; |
51 | 51 | $known->key = array(); |
52 | 52 | $known->value = array(); |
@@ -54,103 +54,103 @@ discard block |
||
54 | 54 | $output = array(); |
55 | 55 | $i = intval(Flatted::index($known, $input, $value)); |
56 | 56 | while ($i < count($input)) { |
57 | - $output[$i] = Flatted::transform($known, $input, $input[$i]); |
|
58 | - $i++; |
|
57 | + $output[$i] = Flatted::transform($known, $input, $input[$i]); |
|
58 | + $i++; |
|
59 | 59 | } |
60 | 60 | return json_encode($output, $options, $depth); |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - // private helpers |
|
64 | - private static function asString($value) { |
|
63 | + // private helpers |
|
64 | + private static function asString($value) { |
|
65 | 65 | return $value instanceof FlattedString ? $value->value : $value; |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - private static function index(&$known, &$input, &$value) { |
|
68 | + private static function index(&$known, &$input, &$value) { |
|
69 | 69 | $input[] = &$value; |
70 | 70 | $index = strval(count($input) - 1); |
71 | 71 | $known->key[] = &$value; |
72 | 72 | $known->value[] = &$index; |
73 | 73 | return $index; |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - private static function keys(&$value) { |
|
76 | + private static function keys(&$value) { |
|
77 | 77 | $obj = new ReflectionObject($value); |
78 | 78 | $props = $obj->getProperties(); |
79 | 79 | $keys = array(); |
80 | 80 | foreach ($props as $prop) |
81 | - $keys[] = $prop->getName(); |
|
81 | + $keys[] = $prop->getName(); |
|
82 | 82 | return $keys; |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - private static function loop($obj, $keys, &$input, &$set, &$output) { |
|
85 | + private static function loop($obj, $keys, &$input, &$set, &$output) { |
|
86 | 86 | foreach ($keys as $key) { |
87 | - $value = $obj ? $output->$key : $output[$key]; |
|
88 | - if ($value instanceof FlattedString) |
|
87 | + $value = $obj ? $output->$key : $output[$key]; |
|
88 | + if ($value instanceof FlattedString) |
|
89 | 89 | Flatted::ref($obj, $key, $input[$value->value], $input, $set, $output); |
90 | 90 | } |
91 | 91 | return $output; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - private static function relate(&$known, &$input, &$value) { |
|
94 | + private static function relate(&$known, &$input, &$value) { |
|
95 | 95 | if (is_string($value) || is_array($value) || is_object($value)) { |
96 | - $key = array_search($value, $known->key, true); |
|
97 | - if ($key !== false) |
|
96 | + $key = array_search($value, $known->key, true); |
|
97 | + if ($key !== false) |
|
98 | 98 | return $known->value[$key]; |
99 | - return Flatted::index($known, $input, $value); |
|
99 | + return Flatted::index($known, $input, $value); |
|
100 | 100 | } |
101 | 101 | return $value; |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - private static function ref($obj, &$key, &$value, &$input, &$set, &$output) { |
|
104 | + private static function ref($obj, &$key, &$value, &$input, &$set, &$output) { |
|
105 | 105 | if (is_array($value) && !in_array($value, $set, true)) { |
106 | - $set[] = $value; |
|
107 | - $value = Flatted::loop(false, array_keys($value), $input, $set, $value); |
|
106 | + $set[] = $value; |
|
107 | + $value = Flatted::loop(false, array_keys($value), $input, $set, $value); |
|
108 | 108 | } |
109 | 109 | elseif (is_object($value) && !in_array($value, $set, true)) { |
110 | - $set[] = $value; |
|
111 | - $value = Flatted::loop(true, Flatted::keys($value), $input, $set, $value); |
|
110 | + $set[] = $value; |
|
111 | + $value = Flatted::loop(true, Flatted::keys($value), $input, $set, $value); |
|
112 | 112 | } |
113 | 113 | if ($obj) { |
114 | - $output->$key = &$value; |
|
114 | + $output->$key = &$value; |
|
115 | 115 | } |
116 | 116 | else { |
117 | - $output[$key] = &$value; |
|
117 | + $output[$key] = &$value; |
|
118 | + } |
|
118 | 119 | } |
119 | - } |
|
120 | 120 | |
121 | - private static function transform(&$known, &$input, &$value) { |
|
121 | + private static function transform(&$known, &$input, &$value) { |
|
122 | 122 | if (is_array($value)) { |
123 | - return array_map( |
|
123 | + return array_map( |
|
124 | 124 | function ($value) use(&$known, &$input) { |
125 | - return Flatted::relate($known, $input, $value); |
|
125 | + return Flatted::relate($known, $input, $value); |
|
126 | 126 | }, |
127 | 127 | $value |
128 | - ); |
|
128 | + ); |
|
129 | 129 | } |
130 | 130 | if (is_object($value)) { |
131 | - $object = new stdClass; |
|
132 | - $keys = Flatted::keys($value); |
|
133 | - foreach ($keys as $key) |
|
131 | + $object = new stdClass; |
|
132 | + $keys = Flatted::keys($value); |
|
133 | + foreach ($keys as $key) |
|
134 | 134 | $object->$key = Flatted::relate($known, $input, $value->$key); |
135 | - return $object; |
|
135 | + return $object; |
|
136 | 136 | } |
137 | 137 | return $value; |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - private static function wrap($value) { |
|
140 | + private static function wrap($value) { |
|
141 | 141 | if (is_string($value)) { |
142 | - return new FlattedString($value); |
|
142 | + return new FlattedString($value); |
|
143 | 143 | } |
144 | 144 | if (is_array($value)) { |
145 | - return array_map('Flatted::wrap', $value); |
|
145 | + return array_map('Flatted::wrap', $value); |
|
146 | 146 | } |
147 | 147 | if (is_object($value)) { |
148 | - $keys = Flatted::keys($value); |
|
149 | - foreach ($keys as $key) { |
|
148 | + $keys = Flatted::keys($value); |
|
149 | + foreach ($keys as $key) { |
|
150 | 150 | $value->$key = self::wrap($value->$key); |
151 | - } |
|
151 | + } |
|
152 | 152 | } |
153 | 153 | return $value; |
154 | - } |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | ?> |
157 | 157 | \ No newline at end of file |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | |
455 | 455 | try { |
456 | 456 | return Vite::useBuildDirectory(config('admin.vite.build_path', 'build')) |
457 | - ->withEntryPoints(static::$viteAssets['css']) |
|
458 | - ->toHtml(); |
|
457 | + ->withEntryPoints(static::$viteAssets['css']) |
|
458 | + ->toHtml(); |
|
459 | 459 | } catch (\Exception $e) { |
460 | 460 | // Fallback to legacy assets if Vite fails |
461 | 461 | return ''; |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | |
476 | 476 | try { |
477 | 477 | return Vite::useBuildDirectory(config('admin.vite.build_path', 'build')) |
478 | - ->withEntryPoints(static::$viteAssets['js']) |
|
479 | - ->toHtml(); |
|
478 | + ->withEntryPoints(static::$viteAssets['js']) |
|
479 | + ->toHtml(); |
|
480 | 480 | } catch (\Exception $e) { |
481 | 481 | // Fallback to legacy assets if Vite fails |
482 | 482 | return ''; |