File tree Expand file tree Collapse file tree 3 files changed +52
-2
lines changed Expand file tree Collapse file tree 3 files changed +52
-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 $ loaderPath = null )
18
18
{
19
+ if ($ loaderPath !== null ) {
20
+ $ loaderClass = self ::getLoaderClassFromPath ($ loaderPath );
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,25 @@ public static function load(string $path)
38
46
39
47
return null ;
40
48
}
49
+
50
+ private static function getLoaderClassFromPath (string $ path )
51
+ {
52
+ if (! file_exists ($ path )) {
53
+ return null ;
54
+ }
55
+
56
+ $ declaredClassesBefore = get_declared_classes ();
57
+
58
+ require_once $ path ;
59
+
60
+ $ declaredClassesAfter = get_declared_classes ();
61
+
62
+ $ newClasses = array_diff ($ declaredClassesAfter , $ declaredClassesBefore );
63
+
64
+ if (empty ($ newClasses )) {
65
+ return null ;
66
+ }
67
+
68
+ return reset ($ newClasses );
69
+ }
41
70
}
You can’t perform that action at this time.
0 commit comments