File tree Expand file tree Collapse file tree 3 files changed +75
-30
lines changed
Expand file tree Collapse file tree 3 files changed +75
-30
lines changed Original file line number Diff line number Diff line change 77use Closure ;
88use Fraction \Exceptions \ActionNotRegistered ;
99use Fraction \Exceptions \UnallowedActionDuplication ;
10+ use Fraction \Support \Bootable ;
1011use Fraction \Support \FractionName ;
1112use Illuminate \Foundation \Application ;
1213use UnitEnum ;
@@ -61,35 +62,6 @@ public function get(string|UnitEnum $action): mixed
6162 */
6263 public function boot (): void
6364 {
64- $ cached = [];
65-
66- if ($ this ->application ->isProduction () && file_exists ($ path = base_path ('bootstrap/cache/actions.php ' ))) {
67- $ files = require $ path ;
68-
69- foreach ($ files as $ file ) {
70- require_once $ file ;
71- }
72- } else {
73- $ files = glob (config ('fraction.path ' ).'/*.php ' );
74-
75- foreach ($ files as $ file ) {
76- $ content = file_get_contents ($ file );
77-
78- if (mb_strpos ($ content , 'namespace ' ) !== false || mb_strpos ($ content , 'execute ' ) === false ) {
79- continue ;
80- }
81-
82- $ cached [] = $ file ;
83-
84- require_once $ file ;
85- }
86-
87- if ($ cached !== []) {
88- file_put_contents (
89- base_path ('bootstrap/cache/actions.php ' ),
90- '<?php return ' .var_export ($ cached , true ).'; '
91- );
92- }
93- }
65+ Bootable::fire ($ this ->application );
9466 }
9567}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Fraction \Support ;
6+
7+ use Illuminate \Foundation \Application ;
8+
9+ /** @internal */
10+ final readonly class Bootable
11+ {
12+ public function __construct (private Application $ application )
13+ {
14+ //
15+ }
16+
17+ /**
18+ * Boot the fraction.
19+ */
20+ public static function fire (Application $ application ): void
21+ {
22+ $ class = new self ($ application );
23+
24+ $ files = $ class ->files ();
25+
26+ $ class ->require ($ files );
27+ }
28+
29+ /**
30+ * Get the files to be booted.
31+ */
32+ private function files (): mixed
33+ {
34+ if ($ this ->application ->isProduction () && file_exists ($ path = base_path ('bootstrap/cache/actions.php ' ))) {
35+ return require $ path ;
36+ }
37+
38+ return glob (config ('fraction.path ' ).'/*.php ' );
39+ }
40+
41+ /**
42+ * Require the files and cache them.
43+ */
44+ private function require (array $ files ): void
45+ {
46+ $ cached = [];
47+
48+ foreach ($ files as $ file ) {
49+ $ cached [] = $ file ;
50+
51+ require_once $ file ;
52+ }
53+
54+ if ($ this ->application ->isProduction () && $ cached !== []) {
55+ file_put_contents (
56+ base_path ('bootstrap/cache/actions.php ' ),
57+ '<?php return ' .var_export ($ cached , true ).'; '
58+ );
59+ }
60+ }
61+ }
Original file line number Diff line number Diff line change 2121use Fraction \Handlers \AsSync ;
2222use Fraction \Handlers \Concerns \ShareableInterpreter ;
2323use Fraction \Jobs \FractionJob ;
24+ use Fraction \Support \Bootable ;
2425use Fraction \Support \DependencyResolver ;
2526use Fraction \Support \FractionName ;
2627use Fraction \ValueObjects \Then ;
128129 expect ($ content )->toBe ($ original );
129130});
130131
132+ arch ()
133+ ->expect (Bootable::class)
134+ ->toBeFinal ()
135+ ->toHaveConstructor ()
136+ ->toOnlyBeUsedIn (FractionManager::class)
137+ ->toHaveMethods ([
138+ 'files ' ,
139+ 'files ' ,
140+ 'require ' ,
141+ ]);
142+
131143arch ()
132144 ->expect (DependencyResolver::class)
133145 ->toBeFinal ()
You can’t perform that action at this time.
0 commit comments