20
20
use Lucid \Console \Components \Job ;
21
21
use Symfony \Component \Finder \Finder as SymfonyFinder ;
22
22
23
+ define ('DS ' , DIRECTORY_SEPARATOR );
24
+
23
25
/**
24
26
* @author Abed Halawi <[email protected] >
25
27
*/
@@ -104,6 +106,31 @@ private function mapFuzzyResults($results)
104
106
}, $ results );
105
107
}
106
108
109
+ /**
110
+ * Get the source directory name.
111
+ * In a microservice installation this will be `app`. `src` otherwise.
112
+ *
113
+ * @return string
114
+ */
115
+ public function getSourceDirectoryName ()
116
+ {
117
+ if (file_exists (base_path ().'/ ' .$ this ->srcDirectoryName )) {
118
+ return $ this ->srcDirectoryName ;
119
+ }
120
+
121
+ return 'app ' ;
122
+ }
123
+
124
+ /**
125
+ * Determines whether this is a lucid microservice installation.
126
+ *
127
+ * @return bool
128
+ */
129
+ public function isMicroservice ()
130
+ {
131
+ return !($ this ->getSourceDirectoryName () === $ this ->srcDirectoryName );
132
+ }
133
+
107
134
/**
108
135
* Get the namespace used for the application.
109
136
*
@@ -118,7 +145,7 @@ public function findRootNamespace()
118
145
119
146
// see which one refers to the "src/" directory
120
147
foreach ($ composer ['autoload ' ]['psr-4 ' ] as $ namespace => $ directory ) {
121
- if ($ directory === $ this ->srcDirectoryName .'/ ' ) {
148
+ if ($ directory === $ this ->getSourceDirectoryName () .'/ ' ) {
122
149
return trim ($ namespace , '\\' );
123
150
}
124
151
}
@@ -145,7 +172,9 @@ public function findFoundationNamespace()
145
172
*/
146
173
public function findServiceNamespace ($ service )
147
174
{
148
- return $ this ->findRootNamespace ().'\\Services \\' .$ service ;
175
+ $ root = $ this ->findRootNamespace ();
176
+
177
+ return (!$ service ) ? $ root : "$ root \\Services \\$ service " ;
149
178
}
150
179
151
180
/**
@@ -155,7 +184,7 @@ public function findServiceNamespace($service)
155
184
*/
156
185
public function findSourceRoot ()
157
186
{
158
- return base_path ().'/ ' .$ this ->srcDirectoryName ;
187
+ return ( $ this -> isMicroservice ()) ? app_path () : base_path ().'/ ' .$ this ->srcDirectoryName ;
159
188
}
160
189
161
190
/**
@@ -170,14 +199,15 @@ public function findServicesRootPath()
170
199
171
200
/**
172
201
* Find the path to the directory of the given service name.
202
+ * In the case of a microservice service installation this will be app path.
173
203
*
174
204
* @param string $service
175
205
*
176
206
* @return string
177
207
*/
178
208
public function findServicePath ($ service )
179
209
{
180
- return $ this ->findServicesRootPath ()."/ $ service " ;
210
+ return (! $ service ) ? app_path () : $ this ->findServicesRootPath ()."/ $ service " ;
181
211
}
182
212
183
213
/**
@@ -215,7 +245,9 @@ public function findFeaturePath($service, $feature)
215
245
*/
216
246
public function findFeatureTestPath ($ service , $ test )
217
247
{
218
- return $ this ->findServicePath ($ service )."/Tests/Features/ $ test.php " ;
248
+ $ root = ($ service ) ? $ this ->findServicePath ($ service ).'/Tests ' : base_path ().'/tests ' ;
249
+
250
+ return "$ root/Features/ $ test.php " ;
219
251
}
220
252
221
253
/**
@@ -347,7 +379,7 @@ public function listJobs($domainName = null)
347
379
*/
348
380
public function findJobPath ($ domain , $ job )
349
381
{
350
- return $ this ->findDomainPath ($ domain ).' / Jobs/ ' .$ job .'.php ' ;
382
+ return $ this ->findDomainPath ($ domain ).DS . ' Jobs ' . DS .$ job .'.php ' ;
351
383
}
352
384
353
385
/**
@@ -386,6 +418,22 @@ public function findDomainJobsTestsNamespace($domain)
386
418
return $ this ->findDomainNamespace ($ domain ).'\Tests\Jobs ' ;
387
419
}
388
420
421
+ /**
422
+ * Get the path to the tests of the given domain.
423
+ *
424
+ * @param string $domain
425
+ *
426
+ * @return string
427
+ */
428
+ public function findDomainTestsPath ($ domain )
429
+ {
430
+ if ($ this ->isMicroservice ()) {
431
+ return base_path ().DS .'tests ' .DS .'Domains ' .DS .$ domain ;
432
+ }
433
+
434
+ return $ this ->findDomainPath ($ domain ).DS .'Tests ' ;
435
+ }
436
+
389
437
/**
390
438
* Find the test path for the given job.
391
439
*
@@ -396,7 +444,7 @@ public function findDomainJobsTestsNamespace($domain)
396
444
*/
397
445
public function findJobTestPath ($ domain , $ jobTest )
398
446
{
399
- return $ this ->findDomainPath ($ domain ).DIRECTORY_SEPARATOR . ' Tests ' . DIRECTORY_SEPARATOR . ' Jobs ' .DIRECTORY_SEPARATOR .$ jobTest .'.php ' ;
447
+ return $ this ->findDomainTestsPath ($ domain ).DS . ' Jobs ' .DS .$ jobTest .'.php ' ;
400
448
}
401
449
402
450
/**
@@ -507,7 +555,7 @@ public function findFeature($name)
507
555
$ files = $ finder ->name ($ fileName )->in ($ this ->findServicesRootPath ())->files ();
508
556
foreach ($ files as $ file ) {
509
557
$ path = $ file ->getRealPath ();
510
- $ serviceName = strstr ($ file ->getRelativePath (), DIRECTORY_SEPARATOR , true );
558
+ $ serviceName = strstr ($ file ->getRelativePath (), DS , true );
511
559
$ service = $ this ->findService ($ serviceName );
512
560
$ content = file_get_contents ($ path );
513
561
0 commit comments