4
4
5
5
use Composer \DependencyResolver \Operation \UninstallOperation ;
6
6
use Composer \DependencyResolver \Operation \UpdateOperation ;
7
+ use Composer \Json \JsonFile ;
7
8
use Composer \Package \PackageInterface ;
8
9
use Narrowspark \Automatic \Common \Contract \Package as PackageContract ;
9
10
use Narrowspark \Automatic \Common \Package ;
10
11
11
- class OperationsResolver
12
+ final class OperationsResolver
12
13
{
13
14
/**
14
15
* A lock instance.
@@ -18,33 +19,22 @@ class OperationsResolver
18
19
private $ lock ;
19
20
20
21
/**
21
- * Name of the parent package .
22
+ * The composer vendor dir .
22
23
*
23
24
* @var string
24
25
*/
25
- private $ parentName ;
26
+ private $ vendorDir ;
26
27
27
28
/**
28
29
* Create a new OperationsResolver instance.
29
30
*
30
31
* @param \Narrowspark\Automatic\Lock $lock
32
+ * @param string $vendorDir
31
33
*/
32
- public function __construct (Lock $ lock )
34
+ public function __construct (Lock $ lock, string $ vendorDir )
33
35
{
34
- $ this ->lock = $ lock ;
35
- }
36
-
37
- /**
38
- * Set the parent package name.
39
- * This is used for the "extraDependencyOf" key.
40
- *
41
- * @param string $name
42
- *
43
- * @return void
44
- */
45
- public function setParentPackageName (string $ name ): void
46
- {
47
- $ this ->parentName = $ name ;
36
+ $ this ->lock = $ lock ;
37
+ $ this ->vendorDir = $ vendorDir ;
48
38
}
49
39
50
40
/**
@@ -72,16 +62,17 @@ public function resolve(array $operations): array
72
62
$ composerPackage = $ operation ->getPackage ();
73
63
}
74
64
75
- if (! isset ($ composerPackage ->getExtra ()['automatic ' ])) {
65
+ $ name = $ composerPackage ->getName ();
66
+ $ automaticFile = $ this ->vendorDir . \DIRECTORY_SEPARATOR . $ name . \DIRECTORY_SEPARATOR . 'automatic.json ' ;
67
+
68
+ if (! \file_exists ($ automaticFile ) && ! isset ($ composerPackage ->getExtra ()['automatic ' ])) {
76
69
continue ;
77
70
}
78
71
79
- $ name = $ composerPackage ->getName ();
80
-
81
- if ($ operation instanceof UninstallOperation && $ this ->lock ->has ($ name )) {
82
- $ package = Package::createFromLock ($ name , (array ) $ this ->lock ->get ($ name ));
72
+ if ($ operation instanceof UninstallOperation && $ this ->lock ->has (Automatic::LOCK_PACKAGES , $ name )) {
73
+ $ package = Package::createFromLock ($ name , (array ) $ this ->lock ->get (Automatic::LOCK_PACKAGES , $ name ));
83
74
} else {
84
- $ package = $ this ->createAutomaticPackage ($ composerPackage );
75
+ $ package = $ this ->createAutomaticPackage ($ composerPackage, $ automaticFile );
85
76
}
86
77
87
78
$ package ->setOperation ($ o );
@@ -122,10 +113,11 @@ private function getPackageVersion(PackageInterface $package): string
122
113
* Create a automatic package with the composer package data.
123
114
*
124
115
* @param \Composer\Package\PackageInterface $composerPackage
116
+ * @param string $automaticFile
125
117
*
126
118
* @return \Narrowspark\Automatic\Common\Contract\Package
127
119
*/
128
- private function createAutomaticPackage (PackageInterface $ composerPackage ): PackageContract
120
+ private function createAutomaticPackage (PackageInterface $ composerPackage, string $ automaticFile ): PackageContract
129
121
{
130
122
$ package = new Package ($ composerPackage ->getName (), $ this ->getPackageVersion ($ composerPackage ));
131
123
$ requires = [];
@@ -152,12 +144,12 @@ private function createAutomaticPackage(PackageInterface $composerPackage): Pack
152
144
$ package ->setUrl ($ url );
153
145
}
154
146
155
- if ($ this ->parentName !== null ) {
156
- $ package ->setParentName ($ this ->parentName );
147
+ if (\file_exists ($ automaticFile )) {
148
+ $ package ->setConfig (JsonFile::parseJson ((string ) \file_get_contents ($ automaticFile )));
149
+ } else {
150
+ $ package ->setConfig ($ composerPackage ->getExtra ()['automatic ' ]);
157
151
}
158
152
159
- $ package ->setConfig ($ composerPackage ->getExtra ()['automatic ' ]);
160
-
161
153
return $ package ;
162
154
}
163
155
}
0 commit comments