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);
 }
 /**
  * Generate the file.
  *
  * @param $name
  * @return Model|bool
  * @throws Exception
  */
 public function generate($name)
 {
     $model = Str::model($name);
     $path = $this->findModelPath($model);
     if ($this->exists($path)) {
         throw new Exception('Model already exists');
         return false;
     }
     $namespace = $this->findModelNamespace();
     $content = file_get_contents($this->getStub());
     $content = str_replace(['{{model}}', '{{namespace}}', '{{foundation_namespace}}'], [$model, $namespace, $this->findFoundationNamespace()], $content);
     $this->createFile($path, $content);
     return new Model($model, $namespace, basename($path), $path, $this->relativeFromReal($path), $content);
 }
 public function generate($name, $service, $plain = false)
 {
     $name = Str::controller($name);
     $service = Str::service($service);
     $path = $this->findControllerPath($service, $name);
     if ($this->exists($path)) {
         throw new Exception('Controller already exists!');
         return false;
     }
     $namespace = $this->findControllerNamespace($service);
     $content = file_get_contents($this->getStub($plain));
     $content = str_replace(['{{controller}}', '{{namespace}}', '{{foundation_namespace}}'], [$name, $namespace, $this->findFoundationNamespace()], $content);
     $this->createFile($path, $content);
     return $this->relativeFromReal($path);
 }
 /**
  * Generate the file.
  *
  * @param string $name
  * @param string $service
  * @return Request|bool
  * @throws Exception
  */
 public function generate($name, $service)
 {
     $request = Str::request($name);
     $service = Str::service($service);
     $path = $this->findRequestPath($service, $request);
     if ($this->exists($path)) {
         throw new Exception('Request already exists');
         return false;
     }
     $namespace = $this->findRequestsNamespace($service);
     $content = file_get_contents($this->getStub());
     $content = str_replace(['{{request}}', '{{namespace}}', '{{foundation_namespace}}'], [$request, $namespace, $this->findFoundationNamespace()], $content);
     $this->createFile($path, $content);
     return new Request($request, $service, $namespace, basename($path), $path, $this->relativeFromReal($path), $content);
 }
 /**
  * Generate the file.
  *
  * @param $name
  * @return Policy|bool
  * @throws Exception
  */
 public function generate($name)
 {
     $policy = Str::policy($name);
     $path = $this->findPolicyPath($policy);
     if ($this->exists($path)) {
         throw new Exception('Policy already exists');
         return false;
     }
     $this->createPolicyDirectory();
     $namespace = $this->findPolicyNamespace();
     $content = file_get_contents($this->getStub());
     $content = str_replace(['{{policy}}', '{{namespace}}', '{{foundation_namespace}}'], [$policy, $namespace, $this->findFoundationNamespace()], $content);
     $this->createFile($path, $content);
     return new Policy($policy, $namespace, basename($path), $path, $this->relativeFromReal($path), $content);
 }
 /**
  * Execute the console command.
  *
  * @return bool|null
  */
 public function fire()
 {
     if ($this->isMicroservice()) {
         return $this->error('This functionality is disabled in a Microservice');
     }
     try {
         $name = Str::service($this->argument('name'));
         if (!$this->exists($service = $this->findServicePath($name))) {
             return $this->error('Service ' . $name . ' cannot be found.');
         }
         $this->delete($service);
         $this->info('Service <comment>' . $name . '</comment> deleted successfully.' . "\n");
         $this->info('Please remove your registered service providers, if any.');
     } catch (\Exception $e) {
         dd($e->getMessage(), $e->getFile(), $e->getLine());
     }
 }
 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);
 }
 public function generate($name)
 {
     $name = Str::service($name);
     $slug = snake_case($name);
     $path = $this->findServicePath($name);
     if ($this->exists($path)) {
         throw new Exception('Service already exists!');
         return false;
     }
     // create service directory
     $this->createDirectory($path);
     // create .gitkeep file in it
     $this->createFile($path . '/.gitkeep');
     $this->createServiceDirectories($path);
     $this->addServiceProviders($name, $slug, $path);
     $this->addRoutesFile($name, $slug, $path);
     $this->addWelcomeViewFile($path);
     return new Service($name, $slug, $path, $this->relativeFromReal($path));
 }
 /**
  * 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);
 }
 /**
  * Parse the model name.
  *
  * @param string $name
  * @return string
  */
 public function parseModelName($name)
 {
     return Str::model($name);
 }
 /**
  * Parse the model name.
  *
  * @param string $name
  * @return string
  */
 public function parseRequestName($name)
 {
     return Str::request($name);
 }
 /**
  * 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 #13
0
     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
Exemple #14
0
 /**
  * Get the list of features,
  * optionally withing a specified service.
  *
  * @param string $serviceName
  *
  * @return \Illuminate\Support\Collection
  *
  * @throws \Exception
  */
 public function listFeatures($serviceName = '')
 {
     $services = $this->listServices();
     if (!empty($serviceName)) {
         $services = $services->filter(function ($service) use($serviceName) {
             return $service->name === $serviceName || $service->slug === $serviceName;
         });
         if ($services->isEmpty()) {
             throw new InvalidArgumentException('Service "' . $serviceName . '" could not be found.');
         }
     }
     $features = [];
     foreach ($services as $service) {
         $serviceFeatures = new Collection();
         $finder = new SymfonyFinder();
         $files = $finder->name('*Feature.php')->in($this->findFeaturesRootPath($service->name))->files();
         foreach ($files as $file) {
             $fileName = $file->getRelativePathName();
             $title = Str::realName($fileName, '/Feature.php/');
             $realPath = $file->getRealPath();
             $relativePath = $this->relativeFromReal($realPath);
             $serviceFeatures->push(new Feature($title, $fileName, $realPath, $relativePath, $service));
         }
         // add to the features array as [service_name => Collection(Feature)]
         $features[$service->name] = $serviceFeatures;
     }
     return $features;
 }
 /**
  * Parse the model name.
  *
  * @param string $name
  * @return string
  */
 public function parsePolicyName($name)
 {
     return Str::policy($name);
 }