Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Add ObserverCommand and RuleCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
pactode committed Jun 19, 2019
1 parent 3960b8e commit 6d90d9c
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/domain-commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

'model' => null,

'observer' => null,

'rule' => null,

],

];
89 changes: 89 additions & 0 deletions src/Commands/ObserverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Signifly\Console\Commands;

use Symfony\Component\Console\Input\InputOption;
use Illuminate\Foundation\Console\ObserverMakeCommand;

class ObserverCommand extends ObserverMakeCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'domain:observer';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new observer class for a given domain';

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
if ($domain = $this->option('domain')) {
return "{$rootNamespace}\\{$domain}\\Observers";
}

$defaultNamespace = config('domain-commands.default_namespace');

return "{$rootNamespace}\\{$defaultNamespace}\\Observers";
}

/**
* Get the destination class path.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
return $this->laravel->basePath().'/app/'.str_replace('\\', '/', $name).'.php';
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
$stubPath = config('domain-commands.stubs.rule');

if (! is_null($stubPath) && is_string($stubPath)) {
return $stubPath;
}

return parent::getStub();
}

/**
* Get the root namespace for the class.
*
* @return string
*/
protected function rootNamespace()
{
return 'Domain\\';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array_merge(parent::getOptions(), [
['domain', 'd', InputOption::VALUE_OPTIONAL, 'Set the domain of the model'],
]);
}
}
89 changes: 89 additions & 0 deletions src/Commands/RuleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Signifly\Console\Commands;

use Symfony\Component\Console\Input\InputOption;
use Illuminate\Foundation\Console\RuleMakeCommand;

class RuleCommand extends RuleMakeCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'domain:rule';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new validation rule for a given domain';

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
if ($domain = $this->option('domain')) {
return "{$rootNamespace}\\{$domain}\\Rules";
}

$defaultNamespace = config('domain-commands.default_namespace');

return "{$rootNamespace}\\{$defaultNamespace}\\Rules";
}

/**
* Get the destination class path.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
return $this->laravel->basePath().'/app/'.str_replace('\\', '/', $name).'.php';
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
$stubPath = config('domain-commands.stubs.rule');

if (! is_null($stubPath) && is_string($stubPath)) {
return $stubPath;
}

return parent::getStub();
}

/**
* Get the root namespace for the class.
*
* @return string
*/
protected function rootNamespace()
{
return 'Domain\\';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array_merge(parent::getOptions(), [
['domain', 'd', InputOption::VALUE_OPTIONAL, 'Set the domain of the model'],
]);
}
}
4 changes: 4 additions & 0 deletions src/DomainServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Illuminate\Support\ServiceProvider;
use Signifly\Console\Commands\DTOCommand;
use Signifly\Console\Commands\EnumCommand;
use Signifly\Console\Commands\RuleCommand;
use Signifly\Console\Commands\EventCommand;
use Signifly\Console\Commands\ModelCommand;
use Signifly\Console\Commands\ActionCommand;
use Signifly\Console\Commands\ObserverCommand;

class DomainServiceProvider extends ServiceProvider
{
Expand All @@ -24,6 +26,8 @@ public function boot()
EnumCommand::class,
EventCommand::class,
ModelCommand::class,
ObserverCommand::class,
RuleCommand::class,
]);
}

Expand Down

0 comments on commit 6d90d9c

Please sign in to comment.