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

Commit 79743de

Browse files
authored
Merge pull request #13 from lucid-architecture/operations
add operation and queueable operation commands
2 parents b62f5e9 + 9fb0b1a commit 79743de

File tree

11 files changed

+523
-10
lines changed

11 files changed

+523
-10
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
1717
- **make**
1818
- `make:controller` Create a new resource Controller class in a service
1919
- `make:feature ` Create a new Feature in a service
20+
- `make:operaion ` Create a new Operation in a service
2021
- `make:job ` Create a new Job in a domain
2122
- `make:service ` Create a new Service
2223
- `make:model ` Create a new Model
2324
- `make:request ` Create a new Request in a service
24-
- `make:policy ` Create a new Policy
25+
- `make:policy ` Create a new Policy
2526
- **list**
2627
- `list:features` List the features.
2728
- `list:services` List the services in this project.
2829
- **delete**
2930
- `delete:feature` Delete an existing Feature in a service
31+
- `delete:operaion` Delete an existing Operation in a service
3032
- `delete:job ` Delete an existing Job in a domain
3133
- `delete:service` Delete an existing Service
3234
- `delete:model ` Delete an existing Model

lucid

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ $commands = [
2626
new \Lucid\Console\Commands\RequestDeleteCommand(),
2727
new \Lucid\Console\Commands\PolicyMakeCommand(),
2828
new \Lucid\Console\Commands\PolicyDeleteCommand(),
29+
30+
new \Lucid\Console\Commands\OperationMakeCommand(),
31+
new \Lucid\Console\Commands\OperationDeleteCommand(),
2932
];
3033

3134
$app = new Symfony\Component\Console\Application('Lucid Console', '0.5.0');
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Commands;
13+
14+
use Lucid\Console\Str;
15+
use Lucid\Console\Finder;
16+
use Lucid\Console\Command;
17+
use Lucid\Console\Filesystem;
18+
use Symfony\Component\Console\Input\InputArgument;
19+
use Symfony\Component\Console\Command\Command as SymfonyCommand;
20+
21+
/**
22+
* @author Ali Issa <[email protected]>
23+
*/
24+
class OperationDeleteCommand extends SymfonyCommand
25+
{
26+
use Finder;
27+
use Command;
28+
use Filesystem;
29+
30+
/**
31+
* The console command name.
32+
*
33+
* @var string
34+
*/
35+
protected $name = 'delete:operation';
36+
37+
/**
38+
* The console command description.
39+
*
40+
* @var string
41+
*/
42+
protected $description = 'Delete an existing Operation in a service';
43+
44+
/**
45+
* The type of class being deleted.
46+
*
47+
* @var string
48+
*/
49+
protected $type = 'Operation';
50+
51+
/**
52+
* Execute the console command.
53+
*
54+
* @return bool|null
55+
*/
56+
public function fire()
57+
{
58+
try {
59+
$service = Str::service($this->argument('service'));
60+
$title = $this->parseName($this->argument('operation'));
61+
62+
if (!$this->exists($operation = $this->findOperationPath($service, $title))) {
63+
$this->error('Operation class '.$title.' cannot be found.');
64+
} else {
65+
$this->delete($operation);
66+
67+
$this->info('Operation class <comment>'.$title.'</comment> deleted successfully.');
68+
}
69+
} catch (Exception $e) {
70+
$this->error($e->getMessage());
71+
}
72+
}
73+
74+
/**
75+
* Get the console command arguments.
76+
*
77+
* @return array
78+
*/
79+
protected function getArguments()
80+
{
81+
return [
82+
['operation', InputArgument::REQUIRED, 'The operation\'s name.'],
83+
['service', InputArgument::OPTIONAL, 'The service from which the operation should be deleted.'],
84+
];
85+
}
86+
87+
/**
88+
* Get the stub file for the generator.
89+
*
90+
* @return string
91+
*/
92+
protected function getStub()
93+
{
94+
return __DIR__.'/../Generators/stubs/operation.stub';
95+
}
96+
97+
/**
98+
* Parse the operation name.
99+
* remove the Operation.php suffix if found
100+
* we're adding it ourselves.
101+
*
102+
* @param string $name
103+
*
104+
* @return string
105+
*/
106+
protected function parseName($name)
107+
{
108+
return Str::operation($name);
109+
}
110+
}

src/Commands/OperationMakeCommand.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Commands;
13+
14+
use Lucid\Console\Command;
15+
use Lucid\Console\Filesystem;
16+
use Lucid\Console\Finder;
17+
use Lucid\Console\Generators\OperationGenerator;
18+
use Lucid\Console\Str;
19+
use Symfony\Component\Console\Command\Command as SymfonyCommand;
20+
use Symfony\Component\Console\Input\InputArgument;
21+
use Symfony\Component\Console\Input\InputOption;
22+
23+
/**
24+
* @author Ali Issa <[email protected]>
25+
*/
26+
class OperationMakeCommand extends SymfonyCommand
27+
{
28+
use Finder;
29+
use Command;
30+
use Filesystem;
31+
32+
/**
33+
* The console command name.
34+
*
35+
* @var string
36+
*/
37+
protected $name = 'make:operation {--Q|queue}';
38+
39+
/**
40+
* The console command description.
41+
*
42+
* @var string
43+
*/
44+
protected $description = 'Create a new Operation in a domain';
45+
46+
/**
47+
* The type of class being generated.
48+
*
49+
* @var string
50+
*/
51+
protected $type = 'Operation';
52+
53+
/**
54+
* Execute the console command.
55+
*
56+
* @return bool|null
57+
*/
58+
public function fire()
59+
{
60+
$generator = new OperationGenerator();
61+
62+
$service = studly_case($this->argument('service'));
63+
$title = $this->parseName($this->argument('operation'));
64+
$isQueueable = $this->option('queue');
65+
try {
66+
$operation = $generator->generate($title, $service, $isQueueable);
67+
68+
$this->info(
69+
'Operation class '.$title.' created successfully.'.
70+
"\n".
71+
"\n".
72+
'Find it at <comment>'.$operation->relativePath.'</comment>'."\n"
73+
);
74+
} catch (Exception $e) {
75+
$this->error($e->getMessage());
76+
}
77+
}
78+
79+
public function getArguments()
80+
{
81+
return [
82+
['operation', InputArgument::REQUIRED, 'The operation\'s name.'],
83+
['service', InputArgument::OPTIONAL, 'The service in which the operation should be implemented.'],
84+
];
85+
}
86+
87+
public function getOptions()
88+
{
89+
return [
90+
['queue', 'Q', InputOption::VALUE_NONE, 'Whether a operation is queueable or not.'],
91+
];
92+
}
93+
94+
/**
95+
* Get the stub file for the generator.
96+
*
97+
* @return string
98+
*/
99+
public function getStub()
100+
{
101+
return __DIR__.'/../Generators/stubs/operation.stub';
102+
}
103+
104+
/**
105+
* Parse the operation name.
106+
* remove the Operation.php suffix if found
107+
* we're adding it ourselves.
108+
*
109+
* @param string $name
110+
*
111+
* @return string
112+
*/
113+
protected function parseName($name)
114+
{
115+
return Str::operation($name);
116+
}
117+
}

src/Components/Operation.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Components;
13+
14+
/**
15+
* @author Ali Issa <[email protected]>
16+
*/
17+
class Operation extends Component
18+
{
19+
public function __construct($title, $file, $realPath, $relativePath, Service $service = null, $content = '')
20+
{
21+
$className = str_replace(' ', '', $title).'Operation';
22+
23+
$this->setAttributes([
24+
'title' => $title,
25+
'className' => $className,
26+
'service' => $service,
27+
'file' => $file,
28+
'realPath' => $realPath,
29+
'relativePath' => $relativePath,
30+
'content' => $content,
31+
]);
32+
}
33+
}

0 commit comments

Comments
 (0)