10
10
use Magento \CloudPatches \Composer \MagentoVersion ;
11
11
use Magento \CloudPatches \Filesystem \Filesystem ;
12
12
use Magento \CloudPatches \Patch \Status \StatusPool ;
13
- use Magento \CloudPatches \Shell \ProcessFactory ;
14
- use Symfony \Component \Process \Exception \ProcessFailedException ;
15
13
16
14
/**
17
15
* Applies and reverts patches.
18
16
*/
19
17
class Applier
20
18
{
21
19
/**
22
- * @var ProcessFactory
20
+ * @var PatchCommandInterface
23
21
*/
24
- private $ processFactory ;
22
+ private $ patchCommand ;
25
23
26
24
/**
27
25
* @var GitConverter
@@ -39,18 +37,18 @@ class Applier
39
37
private $ filesystem ;
40
38
41
39
/**
42
- * @param ProcessFactory $processFactory
40
+ * @param PatchCommandInterface $patchCommand
43
41
* @param GitConverter $gitConverter
44
42
* @param MagentoVersion $magentoVersion
45
43
* @param Filesystem $filesystem
46
44
*/
47
45
public function __construct (
48
- ProcessFactory $ processFactory ,
46
+ PatchCommandInterface $ patchCommand ,
49
47
GitConverter $ gitConverter ,
50
48
MagentoVersion $ magentoVersion ,
51
49
Filesystem $ filesystem
52
50
) {
53
- $ this ->processFactory = $ processFactory ;
51
+ $ this ->patchCommand = $ patchCommand ;
54
52
$ this ->gitConverter = $ gitConverter ;
55
53
$ this ->magentoVersion = $ magentoVersion ;
56
54
$ this ->filesystem = $ filesystem ;
@@ -69,13 +67,11 @@ public function apply(string $path, string $id): string
69
67
{
70
68
$ content = $ this ->readContent ($ path );
71
69
try {
72
- $ this ->processFactory ->create (['git ' , 'apply ' ], $ content )
73
- ->mustRun ();
74
- } catch (ProcessFailedException $ exception ) {
70
+ $ this ->patchCommand ->apply ($ content );
71
+ } catch (PatchCommandException $ exception ) {
75
72
try {
76
- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' , '--reverse ' ], $ content )
77
- ->mustRun ();
78
- } catch (ProcessFailedException $ reverseException ) {
73
+ $ this ->patchCommand ->revertCheck ($ content );
74
+ } catch (PatchCommandException $ reverseException ) {
79
75
throw new ApplierException ($ exception ->getMessage (), $ exception ->getCode ());
80
76
}
81
77
@@ -98,13 +94,11 @@ public function revert(string $path, string $id): string
98
94
{
99
95
$ content = $ this ->readContent ($ path );
100
96
try {
101
- $ this ->processFactory ->create (['git ' , 'apply ' , '--reverse ' ], $ content )
102
- ->mustRun ();
103
- } catch (ProcessFailedException $ exception ) {
97
+ $ this ->patchCommand ->revert ($ content );
98
+ } catch (PatchCommandException $ exception ) {
104
99
try {
105
- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ content )
106
- ->mustRun ();
107
- } catch (ProcessFailedException $ applyException ) {
100
+ $ this ->patchCommand ->applyCheck ($ content );
101
+ } catch (PatchCommandException $ applyException ) {
108
102
throw new ApplierException ($ exception ->getMessage (), $ exception ->getCode ());
109
103
}
110
104
@@ -124,13 +118,11 @@ public function status(string $patchContent): string
124
118
{
125
119
$ patchContent = $ this ->prepareContent ($ patchContent );
126
120
try {
127
- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ patchContent )
128
- ->mustRun ();
129
- } catch (ProcessFailedException $ exception ) {
121
+ $ this ->patchCommand ->applyCheck ($ patchContent );
122
+ } catch (PatchCommandException $ exception ) {
130
123
try {
131
- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' , '--reverse ' ], $ patchContent )
132
- ->mustRun ();
133
- } catch (ProcessFailedException $ reverseException ) {
124
+ $ this ->patchCommand ->revertCheck ($ patchContent );
125
+ } catch (PatchCommandException $ reverseException ) {
134
126
return StatusPool::NA ;
135
127
}
136
128
@@ -150,9 +142,8 @@ public function checkApply(string $patchContent): bool
150
142
{
151
143
$ patchContent = $ this ->prepareContent ($ patchContent );
152
144
try {
153
- $ this ->processFactory ->create (['git ' , 'apply ' , '--check ' ], $ patchContent )
154
- ->mustRun ();
155
- } catch (ProcessFailedException $ exception ) {
145
+ $ this ->patchCommand ->applyCheck ($ patchContent );
146
+ } catch (PatchCommandException $ exception ) {
156
147
return false ;
157
148
}
158
149
0 commit comments