1
|
|
|
<?php namespace Anomaly\Streams\Platform\Stream\Console; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
4
|
|
|
use Anomaly\Streams\Platform\Addon\AddonCollection; |
5
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityCollection; |
6
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityController; |
7
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityCriteria; |
8
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityFormBuilder; |
9
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityModel; |
10
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityModelInterface; |
11
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityObserver; |
12
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityPresenter; |
13
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRepository; |
14
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRepositoryInterface; |
15
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRouter; |
16
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRoutes; |
17
|
|
|
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityTableBuilder; |
18
|
|
|
use Illuminate\Console\Command; |
19
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
20
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Make |
25
|
|
|
* |
26
|
|
|
* @link http://anomaly.is/streams-platform |
27
|
|
|
* @author AnomalyLabs, Inc. <[email protected]> |
28
|
|
|
* @author Ryan Thompson <[email protected]> |
29
|
|
|
* @package Anomaly\Streams\Platform\Stream\Console |
30
|
|
|
*/ |
31
|
|
|
class Make extends Command |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
use DispatchesJobs; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The console command name. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $name = 'make:stream'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The console command description. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $description = 'Make a streams entity namespace.'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Execute the console command. |
52
|
|
|
*/ |
53
|
|
|
public function fire(AddonCollection $addons) |
54
|
|
|
{ |
55
|
|
|
$slug = $this->argument('slug'); |
56
|
|
|
$addon = $this->argument('addon'); |
57
|
|
|
|
58
|
|
|
/* @var Addon $addon */ |
59
|
|
|
if (!$addon = $addons->get($addon)) { |
60
|
|
|
throw new \Exception("The addon [{$this->argument('addon')}] could not be found."); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (!$namespace = $this->option('namespace')) { |
64
|
|
|
$namespace = $addon->getSlug(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->dispatch(new WriteEntityModel($addon, $slug, $namespace)); |
68
|
|
|
$this->dispatch(new WriteEntityRoutes($addon, $slug, $namespace)); |
69
|
|
|
$this->dispatch(new WriteEntityRouter($addon, $slug, $namespace)); |
70
|
|
|
$this->dispatch(new WriteEntityObserver($addon, $slug, $namespace)); |
71
|
|
|
$this->dispatch(new WriteEntityCriteria($addon, $slug, $namespace)); |
72
|
|
|
$this->dispatch(new WriteEntityPresenter($addon, $slug, $namespace)); |
73
|
|
|
$this->dispatch(new WriteEntityController($addon, $slug, $namespace)); |
74
|
|
|
$this->dispatch(new WriteEntityCollection($addon, $slug, $namespace)); |
75
|
|
|
$this->dispatch(new WriteEntityRepository($addon, $slug, $namespace)); |
76
|
|
|
$this->dispatch(new WriteEntityFormBuilder($addon, $slug, $namespace)); |
77
|
|
|
$this->dispatch(new WriteEntityTableBuilder($addon, $slug, $namespace)); |
78
|
|
|
$this->dispatch(new WriteEntityModelInterface($addon, $slug, $namespace)); |
79
|
|
|
$this->dispatch(new WriteEntityRepositoryInterface($addon, $slug, $namespace)); |
80
|
|
|
|
81
|
|
|
$this->call( |
82
|
|
|
'make:migration', |
83
|
|
|
[ |
84
|
|
|
'name' => 'create_' . $slug . '_stream', |
85
|
|
|
'--addon' => $addon->getNamespace(), |
86
|
|
|
'--stream' => $slug |
87
|
|
|
] |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the console command arguments. |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
protected function getArguments() |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
['slug', InputArgument::REQUIRED, 'The entity\'s stream slug.'], |
100
|
|
|
['addon', InputArgument::REQUIRED, 'The addon in which to put the new entity namespace.'] |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get the console command options. |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
View Code Duplication |
protected function getOptions() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
return [ |
112
|
|
|
['namespace', null, InputOption::VALUE_OPTIONAL, 'The stream namespace if not the same as the addon.'], |
113
|
|
|
['migration', null, InputOption::VALUE_NONE, 'Indicates if an stream migration should be created.'] |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.