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

Commit a824290

Browse files
authored
Merge pull request #11 from behind-design/data_policy_request
Commands for: Model, Policy & Request
2 parents 07f8dad + efbe2b5 commit a824290

19 files changed

+1081
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
1919
- `make:feature ` Create a new Feature in a service
2020
- `make:job ` Create a new Job in a domain
2121
- `make:service ` Create a new Service
22+
- `make:model ` Create a new Model
23+
- `make:request ` Create a new Request in a service
24+
- `make:policy ` Create a new Policy
2225
- **list**
2326
- `list:features` List the features.
2427
- `list:services` List the services in this project.
2528
- **delete**
2629
- `delete:feature` Delete an existing Feature in a service
2730
- `delete:job ` Delete an existing Job in a domain
2831
- `delete:service` Delete an existing Service
32+
- `delete:model ` Delete an existing Model
33+
- `delete:request ` Delete an existing Request in a service
34+
- `delete:policy ` Delete an existing Policy
2935

3036
### Commands Usage
3137

@@ -34,6 +40,9 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
3440
- `make:feature <feature> [<service>]`
3541
- `make:job <job> <domain>`
3642
- `make:service <name>`
43+
- `make:model <model>`
44+
- `make:request <request> [<service>]`
45+
- `make:policy <policy>`
3746

3847
#### List
3948
- `list:services`
@@ -43,3 +52,6 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
4352
- `delete:service <name>`
4453
- `delete:feature <feature> [<service>]`
4554
- `delete:job <job> <domain>`
55+
- `delete:model <model>`
56+
- `delete:request <request> [<service>]`
57+
- `delete:policy <policy>`

lucid

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ $commands = [
1919
new Lucid\Console\Commands\ControllerMakeCommand(),
2020
new Lucid\Console\Commands\ServicesListCommand(),
2121
new Lucid\Console\Commands\FeaturesListCommand(),
22+
23+
new \Lucid\Console\Commands\ModelMakeCommand(),
24+
new \Lucid\Console\Commands\ModelDeleteCommand(),
25+
new \Lucid\Console\Commands\RequestMakeCommand(),
26+
new \Lucid\Console\Commands\RequestDeleteCommand(),
27+
new \Lucid\Console\Commands\PolicyMakeCommand(),
28+
new \Lucid\Console\Commands\PolicyDeleteCommand(),
2229
];
2330

2431
$app = new Symfony\Component\Console\Application('Lucid Console', '0.5.0');

src/Commands/ModelDeleteCommand.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Lucid\Console\Commands;
4+
5+
use Exception;
6+
use Lucid\Console\Str;
7+
use Lucid\Console\Command;
8+
use Lucid\Console\Filesystem;
9+
use Lucid\Console\Finder;
10+
use Symfony\Component\Console\Command\Command as SymfonyCommand;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
13+
14+
/**
15+
* Class ModelDeleteCommand
16+
*
17+
* @author Bernat Jufré <[email protected]>
18+
*
19+
* @package Lucid\Console\Commands
20+
*/
21+
class ModelDeleteCommand extends SymfonyCommand
22+
{
23+
use Finder;
24+
use Command;
25+
use Filesystem;
26+
27+
/**
28+
* The console command name.
29+
*
30+
* @var string
31+
*/
32+
protected $name = 'delete:model';
33+
34+
/**
35+
* The console command description.
36+
*
37+
* @var string
38+
*/
39+
protected $description = 'Delete an existing Eloquent Model.';
40+
41+
/**
42+
* The type of class being generated
43+
* @var string
44+
*/
45+
protected $type = 'Model';
46+
47+
/**
48+
* Execute the console command.
49+
*
50+
* @return bool|null
51+
*/
52+
public function fire()
53+
{
54+
try {
55+
$model = $this->parseModelName($this->argument('model'));
56+
57+
if ( ! $this->exists($path = $this->findModelPath($model))) {
58+
$this->error('Model class ' . $model . ' cannot be found.');
59+
} else {
60+
$this->delete($path);
61+
62+
$this->info('Model class <comment>' . $model . '</comment> deleted successfully.');
63+
}
64+
} catch (Exception $e) {
65+
$this->error($e->getMessage());
66+
}
67+
}
68+
69+
/**
70+
* Get the console command arguments.
71+
*
72+
* @return array
73+
*/
74+
public function getArguments()
75+
{
76+
return [
77+
['model', InputArgument::REQUIRED, 'The Model\'s name.']
78+
];
79+
}
80+
81+
/**
82+
* Get the stub file for the generator.
83+
*
84+
* @return string
85+
*/
86+
public function getStub()
87+
{
88+
return __DIR__ . '/../Generators/stubs/model.stub';
89+
}
90+
91+
/**
92+
* Parse the model name.
93+
*
94+
* @param string $name
95+
* @return string
96+
*/
97+
public function parseModelName($name)
98+
{
99+
return Str::model($name);
100+
}
101+
}

src/Commands/ModelMakeCommand.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace Lucid\Console\Commands;
4+
5+
use Exception;
6+
use Lucid\Console\Generators\ModelGenerator;
7+
use Lucid\Console\Command;
8+
use Lucid\Console\Filesystem;
9+
use Lucid\Console\Finder;
10+
use Symfony\Component\Console\Command\Command as SymfonyCommand;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
13+
14+
/**
15+
* Class ModelMakeCommand
16+
*
17+
* @author Bernat Jufré <[email protected]>
18+
*
19+
* @package Lucid\Console\Commands
20+
*/
21+
class ModelMakeCommand extends SymfonyCommand
22+
{
23+
use Finder;
24+
use Command;
25+
use Filesystem;
26+
27+
/**
28+
* The console command name.
29+
*
30+
* @var string
31+
*/
32+
protected $name = 'make:model';
33+
34+
/**
35+
* The console command description.
36+
*
37+
* @var string
38+
*/
39+
protected $description = 'Create a new Eloquent Model.';
40+
41+
/**
42+
* The type of class being generated
43+
* @var string
44+
*/
45+
protected $type = 'Model';
46+
47+
/**
48+
* Execute the console command.
49+
*
50+
* @return bool|null
51+
*/
52+
public function fire()
53+
{
54+
$generator = new ModelGenerator();
55+
56+
$name = $this->argument('model');
57+
58+
try {
59+
$model = $generator->generate($name);
60+
61+
$this->info('Model class created successfully.' .
62+
"\n" .
63+
"\n" .
64+
'Find it at <comment>' . $model->relativePath . '</comment>' . "\n"
65+
);
66+
} catch (Exception $e) {
67+
$this->error($e->getMessage());
68+
}
69+
}
70+
71+
/**
72+
* Get the console command arguments.
73+
*
74+
* @return array
75+
*/
76+
public function getArguments()
77+
{
78+
return [
79+
['model', InputArgument::REQUIRED, 'The Model\'s name.']
80+
];
81+
}
82+
83+
/**
84+
* Get the stub file for the generator.
85+
*
86+
* @return string
87+
*/
88+
public function getStub()
89+
{
90+
return __DIR__ . '/../Generators/stubs/model.stub';
91+
}
92+
}

src/Commands/PolicyDeleteCommand.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Lucid\Console\Commands;
4+
5+
use Exception;
6+
use Lucid\Console\Str;
7+
use Lucid\Console\Command;
8+
use Lucid\Console\Filesystem;
9+
use Lucid\Console\Finder;
10+
use Symfony\Component\Console\Command\Command as SymfonyCommand;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
13+
14+
/**
15+
* Class PolicyDeleteCommand
16+
*
17+
* @author Bernat Jufré <[email protected]>
18+
*
19+
* @package Lucid\Console\Commands
20+
*/
21+
class PolicyDeleteCommand extends SymfonyCommand
22+
{
23+
use Finder;
24+
use Command;
25+
use Filesystem;
26+
27+
/**
28+
* The console command name.
29+
*
30+
* @var string
31+
*/
32+
protected $name = 'delete:policy';
33+
34+
/**
35+
* The console command description.
36+
*
37+
* @var string
38+
*/
39+
protected $description = 'Delete an existing Policy.';
40+
41+
/**
42+
* The type of class being generated
43+
* @var string
44+
*/
45+
protected $type = 'Policy';
46+
47+
/**
48+
* Execute the console command.
49+
*
50+
* @return bool|null
51+
*/
52+
public function fire()
53+
{
54+
try {
55+
$policy = $this->parsePolicyName($this->argument('policy'));
56+
57+
if ( ! $this->exists($path = $this->findPolicyPath($policy))) {
58+
$this->error('Policy class ' . $policy . ' cannot be found.');
59+
} else {
60+
$this->delete($path);
61+
62+
$this->info('Policy class <comment>' . $policy . '</comment> deleted successfully.');
63+
}
64+
} catch (Exception $e) {
65+
$this->error($e->getMessage());
66+
}
67+
}
68+
69+
/**
70+
* Get the console command arguments.
71+
*
72+
* @return array
73+
*/
74+
public function getArguments()
75+
{
76+
return [
77+
['policy', InputArgument::REQUIRED, 'The Policy\'s name.']
78+
];
79+
}
80+
81+
/**
82+
* Get the stub file for the generator.
83+
*
84+
* @return string
85+
*/
86+
public function getStub()
87+
{
88+
return __DIR__ . '/../Generators/stubs/policy.stub';
89+
}
90+
91+
/**
92+
* Parse the model name.
93+
*
94+
* @param string $name
95+
* @return string
96+
*/
97+
public function parsePolicyName($name)
98+
{
99+
return Str::policy($name);
100+
}
101+
}

0 commit comments

Comments
 (0)