public function generate($feature, $service, array $jobs = [])
 {
     $feature = Str::feature($feature);
     $service = Str::service($service);
     $path = $this->findFeaturePath($service, $feature);
     if ($this->exists($path)) {
         throw new Exception('Feature already exists!');
         return false;
     }
     $namespace = $this->findFeatureNamespace($service);
     $content = file_get_contents($this->getStub());
     $useJobs = '';
     // stores the `use` statements of the jobs
     $runJobs = '';
     // stores the `$this->run` statements of the jobs
     foreach ($jobs as $index => $job) {
         $useJobs .= 'use ' . $job['namespace'] . '\\' . $job['className'] . ";\n";
         $runJobs .= "\t\t" . '$this->run(' . $job['className'] . '::class);';
         // only add carriage returns when it's not the last job
         if ($index != count($jobs) - 1) {
             $runJobs .= "\n\n";
         }
     }
     $content = str_replace(['{{feature}}', '{{namespace}}', '{{foundation_namespace}}', '{{use_jobs}}', '{{run_jobs}}'], [$feature, $namespace, $this->findFoundationNamespace(), $useJobs, $runJobs], $content);
     $this->createFile($path, $content);
     // generate test file
     $this->generateTestFile($feature, $service);
     return new Feature($feature, basename($path), $path, $this->relativeFromReal($path), $service ? $this->findService($service) : null, $content);
 }
 /**
  * Parse the feature name.
  *  remove the Feature.php suffix if found
  *  we're adding it ourselves.
  *
  * @param string $name
  *
  * @return string
  */
 protected function parseName($name)
 {
     return Str::feature($name);
 }
Exemple #3
0
 /**
  * Find the feature for the given feature name.
  *
  * @param string $name
  *
  * @return \Lucid\Console\Components\Feature
  */
 public function findFeature($name)
 {
     $name = Str::feature($name);
     $fileName = "{$name}.php";
     $finder = new SymfonyFinder();
     $files = $finder->name($fileName)->in($this->findServicesRootPath())->files();
     foreach ($files as $file) {
         $path = $file->getRealPath();
         $serviceName = strstr($file->getRelativePath(), DS, true);
         $service = $this->findService($serviceName);
         $content = file_get_contents($path);
         return new Feature(Str::realName($name, '/Feature/'), $fileName, $path, $this->relativeFromReal($path), $service, $content);
     }
 }