1
|
|
|
<?php namespace Cerbero\Workflow\Console\Commands; |
2
|
|
|
|
3
|
|
|
use Cerbero\Workflow\Repositories\PipelineRepositoryInterface; |
4
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
5
|
|
|
use Cerbero\Workflow\Console\Drawing\Drawer; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
|
8
|
|
|
class ReadWorkflowCommand extends Command { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The console command name. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $name = 'workflow:read'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Show an existing workflow'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Andrea Marco Sartori |
26
|
|
|
* @var Cerbero\Workflow\Repositories\PipelineRepositoryInterface $pipelines Pipeline repository. |
27
|
|
|
*/ |
28
|
|
|
protected $pipelines; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @author Andrea Marco Sartori |
32
|
|
|
* @var Cerbero\Workflow\Console\Drawing\Drawer $drawer The workflow drawer. |
33
|
|
|
*/ |
34
|
|
|
protected $drawer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set the dependencies. |
38
|
|
|
* |
39
|
|
|
* @param \Cerbero\Workflow\Repositories\PipelineRepositoryInterface $pipelines |
40
|
|
|
* @param \Cerbero\Workflow\Console\Drawing\Drawer $drawer |
41
|
|
|
* @return void |
|
|
|
|
42
|
|
|
*/ |
43
|
|
|
public function __construct(PipelineRepositoryInterface $pipelines, Drawer $drawer) |
44
|
|
|
{ |
45
|
|
|
parent::__construct(); |
46
|
|
|
|
47
|
|
|
$this->pipelines = $pipelines; |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->drawer = $drawer; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Execute the console command. |
54
|
|
|
* |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function fire() |
58
|
|
|
{ |
59
|
|
|
$workflow = ucfirst($this->argument('name')); |
60
|
|
|
|
61
|
|
|
if( ! $this->pipelines->exists($workflow)) |
62
|
|
|
{ |
63
|
|
|
return $this->error("The workflow [$workflow] does not exist."); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->info($this->drawer->draw($workflow)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the console command arguments. |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
protected function getArguments() |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
['name', InputArgument::REQUIRED, 'The name of the workflow.'], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.