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); }
/** * Parse the job name. * remove the Job.php suffix if found * we're adding it ourselves. * * @param string $name * * @return string */ protected function parseName($name) { return Str::job($name); }
/** * Find the feature for the given feature name. * * @param string $name * * @return \Lucid\Console\Components\Feature */ public function findJob($name) { $name = Str::job($name); $fileName = "{$name}.php"; $finder = new SymfonyFinder(); $files = $finder->name($fileName)->in($this->findDomainsRootPath())->files(); foreach ($files as $file) { $path = $file->getRealPath(); $domainName = strstr($file->getRelativePath(), DIRECTORY_SEPARATOR, true); $domain = $this->findDomain($domainName); $content = file_get_contents($path); return new Job(Str::realName($name, '/Job/'), $this->findDomainJobsNamespace($domainName), $fileName, $path, $this->relativeFromReal($path), $domain, $content); } }