5
5
use IlluminateAgnostic \Str \Support \Str ;
6
6
use Somnambulist \ProjectManager \Models \Project ;
7
7
use Somnambulist \ProjectManager \Models \Template ;
8
+ use function parse_str ;
8
9
use function sprintf ;
9
10
10
11
/**
@@ -23,11 +24,17 @@ public function installInto(Project $project, Template $template, string $name,
23
24
$ this ->tools ()->step (++$ step , 'creating <info>%s</info> from composer project ' , $ this ->type );
24
25
$ this ->tools ()->warning ('installer scripts will not be run! ' );
25
26
27
+ $ proj = $ this ->getProjectPackage ($ template );
28
+ $ repo = $ this ->getAlternateRepository ($ template );
29
+ $ ver = $ this ->getProjectPackageVersion ($ template );
30
+
26
31
$ res = $ this ->tools ()->execute (
27
32
sprintf (
28
- 'composer create-project --no-scripts --remove-vcs %s %s ' ,
29
- Str::replaceFirst ('composer: ' , '' , $ template ->source ()),
30
- $ cwd
33
+ 'composer create-project --no-scripts --remove-vcs %s %s %s %s ' ,
34
+ $ repo ? '--repository= ' . $ repo : '' ,
35
+ $ proj ,
36
+ $ cwd ,
37
+ $ ver
31
38
),
32
39
dirname ($ cwd )
33
40
);
@@ -49,4 +56,33 @@ public function installInto(Project $project, Template $template, string $name,
49
56
50
57
return $ this ->success ();
51
58
}
59
+
60
+ private function getProjectPackage (Template $ template ): string
61
+ {
62
+ return Str::before (Str::replaceFirst ('composer: ' , '' , $ template ->source ()), '? ' );
63
+ }
64
+
65
+ private function getAlternateRepository (Template $ template ): ?string
66
+ {
67
+ $ options = $ this ->parseTemplateOptions ($ template );
68
+
69
+ return $ options ['repository ' ] ?? null ;
70
+ }
71
+
72
+ private function getProjectPackageVersion (Template $ template ): ?string
73
+ {
74
+ $ options = $ this ->parseTemplateOptions ($ template );
75
+
76
+ return $ options ['version ' ] ?? null ;
77
+ }
78
+
79
+ private function parseTemplateOptions (Template $ template ): array
80
+ {
81
+ $ query = Str::after ($ template ->source (), '? ' );
82
+ $ options = [];
83
+
84
+ parse_str ($ query , $ options );
85
+
86
+ return $ options ;
87
+ }
52
88
}
0 commit comments