File tree Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use TweakPHP \Client \Cli ;
3
4
use TweakPHP \Client \Loader ;
4
5
5
6
require __DIR__ .'/vendor/autoload.php ' ;
11
12
exit (1 );
12
13
}
13
14
14
- $ loader = Loader::load ($ arguments [1 ]);
15
+ $ customLoader = Cli::getArgument ('loader ' );
16
+ $ loader = Loader::load ($ arguments [1 ], $ customLoader );
15
17
16
18
if ($ loader === null ) {
17
19
echo 'Invalid path ' .PHP_EOL ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace TweakPHP \Client ;
4
+
5
+ class Cli
6
+ {
7
+ public static function getArgument (string $ argument ): string
8
+ {
9
+ $ arguments = $ _SERVER ['argv ' ] ?? [];
10
+
11
+ foreach ($ arguments as $ arg ) {
12
+ if (strpos ($ arg , "-- $ argument= " ) === 0 ) {
13
+ return substr ($ arg , strlen ("-- $ argument= " ));
14
+ }
15
+ }
16
+
17
+ return '' ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -14,8 +14,16 @@ class Loader
14
14
/**
15
15
* @return null|LoaderInterface
16
16
*/
17
- public static function load (string $ path )
17
+ public static function load (string $ path, ? string $ encodedLoader = null )
18
18
{
19
+ if ($ encodedLoader !== null ) {
20
+ $ loaderClass = self ::getLoaderClassFrom ($ encodedLoader );
21
+
22
+ if ($ loaderClass !== null ) {
23
+ return new $ loaderClass ($ path );
24
+ }
25
+ }
26
+
19
27
if (LaravelLoader::supports ($ path )) {
20
28
return new LaravelLoader ($ path );
21
29
}
@@ -38,4 +46,18 @@ public static function load(string $path)
38
46
39
47
return null ;
40
48
}
49
+
50
+ private static function getLoaderClassFrom (string $ encodedLoader )
51
+ {
52
+ $ declaredClassesBefore = get_declared_classes ();
53
+ $ loader = base64_decode ($ encodedLoader );
54
+ eval (str_replace ('<?php ' , '' , $ loader ));
55
+ $ declaredClassesAfter = get_declared_classes ();
56
+ $ newClasses = array_diff ($ declaredClassesAfter , $ declaredClassesBefore );
57
+ if (empty ($ newClasses )) {
58
+ return null ;
59
+ }
60
+
61
+ return reset ($ newClasses );
62
+ }
41
63
}
Original file line number Diff line number Diff line change @@ -41,4 +41,9 @@ public function casters(): array
41
41
{
42
42
return [];
43
43
}
44
+
45
+ public static function supports (string $ path ): bool
46
+ {
47
+ return false ;
48
+ }
44
49
}
You can’t perform that action at this time.
0 commit comments