14
14
15
15
class OneTimeOperationManager
16
16
{
17
+ private static $ paths = [];
18
+
17
19
/**
18
20
* @return Collection<OneTimeOperationFile>
19
21
*/
@@ -54,7 +56,13 @@ public static function getUnprocessedFiles(): Collection
54
56
public static function getAllFiles (): Collection
55
57
{
56
58
try {
57
- return collect (File::files (self ::getDirectoryPath ()));
59
+ $ files = [];
60
+
61
+ foreach (self ::getOperationPaths () as $ path ) {
62
+ $ files = array_merge ($ files , File::files ($ path ));
63
+ }
64
+
65
+ return collect ($ files );
58
66
} catch (DirectoryNotFoundException $ e ) {
59
67
return collect ();
60
68
}
@@ -95,7 +103,17 @@ public static function getOperationFileByName(string $operationName): OneTimeOpe
95
103
96
104
public static function pathToFileByName (string $ operationName ): string
97
105
{
98
- return self ::getDirectoryPath ().self ::buildFilename ($ operationName );
106
+ foreach (self ::getOperationPaths () as $ path ) {
107
+ $ path = Str::of ($ path )->rtrim ('/ ' );
108
+ $ fullPath = $ path . DIRECTORY_SEPARATOR . self ::buildFilename ($ operationName );
109
+ if (!file_exists ($ fullPath )) {
110
+ continue ;
111
+ }
112
+
113
+ return $ fullPath ;
114
+ }
115
+
116
+ throw new \RuntimeException ("The operation ' $ operationName' is invalid! " );
99
117
}
100
118
101
119
public static function fileExistsByName (string $ operationName ): bool
@@ -113,6 +131,29 @@ public static function getDirectoryPath(): string
113
131
return App::basePath (Str::of (self ::getDirectoryName ())->rtrim ('/ ' )).DIRECTORY_SEPARATOR ;
114
132
}
115
133
134
+ /**
135
+ * Get all the operation paths.
136
+ *
137
+ * @return array
138
+ */
139
+ public static function getOperationPaths ()
140
+ {
141
+ return array_merge (
142
+ self ::$ paths , [self ::getDirectoryPath ()]
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Register operation paths.
148
+ *
149
+ * @param array|string $paths
150
+ * @return void
151
+ */
152
+ public static function loadOperationsFrom ($ paths )
153
+ {
154
+ self ::$ paths = array_merge (self ::$ paths , (array )$ paths );
155
+ }
156
+
116
157
public static function getOperationNameFromFilename (string $ filename ): string
117
158
{
118
159
return str ($ filename )->remove ('.php ' );
0 commit comments