public function generate($job, $domain) { $job = Str::job($job); $domain = Str::domain($domain); $path = $this->findJobPath($domain, $job); if ($this->exists($path)) { throw new Exception('Job already exists'); return false; } // Make sure the domain directory exists $this->createDomainDirectory($domain); // Create the job $namespace = $this->findDomainJobsNamespace($domain); $content = file_get_contents($this->getStub()); $content = str_replace(['{{job}}', '{{namespace}}', '{{foundation_namespace}}'], [$job, $namespace, $this->findFoundationNamespace()], $content); $this->createFile($path, $content); $this->generateTestFile($job, $domain); return new Job($job, $namespace, basename($path), $path, $this->relativeFromReal($path), $this->findDomain($domain), $content); }
return (new Controller())->listServices(); }); Route::get('/services/{slug}/features', function ($slug) { return (new Controller())->listFeatures($slug); }); Route::post('/services', function () { return app(\Lucid\Console\Generators\ServiceGenerator::class)->generate(request()->input('name'))->toArray(); }); Route::get('/features/{name}', function ($name) { return (new Controller())->findFeature($name)->toArray(); }); Route::get('/domains', function () { return (new Controller())->listDomains(); }); Route::get('/domains/{name}/jobs', function ($name) { return (new Controller())->listJobs(\Lucid\Console\Str::domain($name)); }); Route::get('/jobs', function () { return (new Controller())->listJobs(); }); Route::get('/jobs/{name}', function ($name) { return (new Controller())->findJob($name)->toArray(); }); Route::post('/jobs', function () { // create job $title = request()->input('title'); $domain = request()->input('domain'); return app(\Lucid\Console\Generators\JobGenerator::class)->generate($title, $domain)->toArray(); }); Route::post('/features', function () { // create feature
/** * List the jobs per domain, * optionally provide a domain name to list its jobs. * * @param string $domain * * @return Collection */ public function listJobs($domainName = null) { $domains = $domainName ? [$this->findDomain(Str::domain($domainName))] : $this->listDomains(); $jobs = new Collection(); foreach ($domains as $domain) { $path = $domain->realPath; $finder = new SymfonyFinder(); $files = $finder->name('*Job.php')->in($path . '/Jobs')->files(); $jobs[$domain->name] = new Collection(); foreach ($files as $file) { $name = $file->getRelativePathName(); $job = new Job(Str::realName($name, '/Job.php/'), $this->findDomainJobsNamespace($domain->name), $name, $file->getRealPath(), $this->relativeFromReal($file->getRealPath()), $domain, file_get_contents($file->getRealPath())); $jobs[$domain->name]->push($job); } } return $jobs; }