This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from lucid-architecture/operations
add operation and queueable operation commands
- Loading branch information
Showing
11 changed files
with
523 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the lucid-console project. | ||
* | ||
* (c) Vinelab <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Lucid\Console\Commands; | ||
|
||
use Lucid\Console\Str; | ||
use Lucid\Console\Finder; | ||
use Lucid\Console\Command; | ||
use Lucid\Console\Filesystem; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Command\Command as SymfonyCommand; | ||
|
||
/** | ||
* @author Ali Issa <[email protected]> | ||
*/ | ||
class OperationDeleteCommand extends SymfonyCommand | ||
{ | ||
use Finder; | ||
use Command; | ||
use Filesystem; | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'delete:operation'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete an existing Operation in a service'; | ||
|
||
/** | ||
* The type of class being deleted. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Operation'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return bool|null | ||
*/ | ||
public function fire() | ||
{ | ||
try { | ||
$service = Str::service($this->argument('service')); | ||
$title = $this->parseName($this->argument('operation')); | ||
|
||
if (!$this->exists($operation = $this->findOperationPath($service, $title))) { | ||
$this->error('Operation class '.$title.' cannot be found.'); | ||
} else { | ||
$this->delete($operation); | ||
|
||
$this->info('Operation class <comment>'.$title.'</comment> deleted successfully.'); | ||
} | ||
} catch (Exception $e) { | ||
$this->error($e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Get the console command arguments. | ||
* | ||
* @return array | ||
*/ | ||
protected function getArguments() | ||
{ | ||
return [ | ||
['operation', InputArgument::REQUIRED, 'The operation\'s name.'], | ||
['service', InputArgument::OPTIONAL, 'The service from which the operation should be deleted.'], | ||
]; | ||
} | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return __DIR__.'/../Generators/stubs/operation.stub'; | ||
} | ||
|
||
/** | ||
* Parse the operation name. | ||
* remove the Operation.php suffix if found | ||
* we're adding it ourselves. | ||
* | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
protected function parseName($name) | ||
{ | ||
return Str::operation($name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the lucid-console project. | ||
* | ||
* (c) Vinelab <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Lucid\Console\Commands; | ||
|
||
use Lucid\Console\Command; | ||
use Lucid\Console\Filesystem; | ||
use Lucid\Console\Finder; | ||
use Lucid\Console\Generators\OperationGenerator; | ||
use Lucid\Console\Str; | ||
use Symfony\Component\Console\Command\Command as SymfonyCommand; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* @author Ali Issa <[email protected]> | ||
*/ | ||
class OperationMakeCommand extends SymfonyCommand | ||
{ | ||
use Finder; | ||
use Command; | ||
use Filesystem; | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:operation {--Q|queue}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new Operation in a domain'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Operation'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return bool|null | ||
*/ | ||
public function fire() | ||
{ | ||
$generator = new OperationGenerator(); | ||
|
||
$service = studly_case($this->argument('service')); | ||
$title = $this->parseName($this->argument('operation')); | ||
$isQueueable = $this->option('queue'); | ||
try { | ||
$operation = $generator->generate($title, $service, $isQueueable); | ||
|
||
$this->info( | ||
'Operation class '.$title.' created successfully.'. | ||
"\n". | ||
"\n". | ||
'Find it at <comment>'.$operation->relativePath.'</comment>'."\n" | ||
); | ||
} catch (Exception $e) { | ||
$this->error($e->getMessage()); | ||
} | ||
} | ||
|
||
public function getArguments() | ||
{ | ||
return [ | ||
['operation', InputArgument::REQUIRED, 'The operation\'s name.'], | ||
['service', InputArgument::OPTIONAL, 'The service in which the operation should be implemented.'], | ||
]; | ||
} | ||
|
||
public function getOptions() | ||
{ | ||
return [ | ||
['queue', 'Q', InputOption::VALUE_NONE, 'Whether a operation is queueable or not.'], | ||
]; | ||
} | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
public function getStub() | ||
{ | ||
return __DIR__.'/../Generators/stubs/operation.stub'; | ||
} | ||
|
||
/** | ||
* Parse the operation name. | ||
* remove the Operation.php suffix if found | ||
* we're adding it ourselves. | ||
* | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
protected function parseName($name) | ||
{ | ||
return Str::operation($name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the lucid-console project. | ||
* | ||
* (c) Vinelab <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Lucid\Console\Components; | ||
|
||
/** | ||
* @author Ali Issa <[email protected]> | ||
*/ | ||
class Operation extends Component | ||
{ | ||
public function __construct($title, $file, $realPath, $relativePath, Service $service = null, $content = '') | ||
{ | ||
$className = str_replace(' ', '', $title).'Operation'; | ||
|
||
$this->setAttributes([ | ||
'title' => $title, | ||
'className' => $className, | ||
'service' => $service, | ||
'file' => $file, | ||
'realPath' => $realPath, | ||
'relativePath' => $relativePath, | ||
'content' => $content, | ||
]); | ||
} | ||
} |
Oops, something went wrong.