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

Commit

Permalink
Merge pull request #13 from lucid-architecture/operations
Browse files Browse the repository at this point in the history
add operation and queueable operation commands
  • Loading branch information
Mulkave authored Dec 12, 2016
2 parents b62f5e9 + 9fb0b1a commit 79743de
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
- **make**
- `make:controller` Create a new resource Controller class in a service
- `make:feature ` Create a new Feature in a service
- `make:operaion ` Create a new Operation in a service
- `make:job ` Create a new Job in a domain
- `make:service ` Create a new Service
- `make:model ` Create a new Model
- `make:request ` Create a new Request in a service
- `make:policy ` Create a new Policy
- `make:policy ` Create a new Policy
- **list**
- `list:features` List the features.
- `list:services` List the services in this project.
- **delete**
- `delete:feature` Delete an existing Feature in a service
- `delete:operaion` Delete an existing Operation in a service
- `delete:job ` Delete an existing Job in a domain
- `delete:service` Delete an existing Service
- `delete:model ` Delete an existing Model
Expand Down
3 changes: 3 additions & 0 deletions lucid
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ $commands = [
new \Lucid\Console\Commands\RequestDeleteCommand(),
new \Lucid\Console\Commands\PolicyMakeCommand(),
new \Lucid\Console\Commands\PolicyDeleteCommand(),

new \Lucid\Console\Commands\OperationMakeCommand(),
new \Lucid\Console\Commands\OperationDeleteCommand(),
];

$app = new Symfony\Component\Console\Application('Lucid Console', '0.5.0');
Expand Down
110 changes: 110 additions & 0 deletions src/Commands/OperationDeleteCommand.php
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);
}
}
117 changes: 117 additions & 0 deletions src/Commands/OperationMakeCommand.php
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);
}
}
33 changes: 33 additions & 0 deletions src/Components/Operation.php
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,
]);
}
}
Loading

0 comments on commit 79743de

Please sign in to comment.