1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fenos\Notifynder\Artisan; |
4
|
|
|
|
5
|
|
|
use Fenos\Notifynder\Contracts\NotifynderCategory; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class CreateCategory extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'notifynder:create:category'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create and store a new notifynder category'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \\Fenos\Notifynder\Contracts\NotifynderCategory |
27
|
|
|
*/ |
28
|
|
|
private $notifynderCategory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new command instance. |
32
|
|
|
* |
33
|
|
|
* @param NotifynderCategory $notifynderCategory |
34
|
|
|
* @return \Fenos\Notifynder\Artisan\CreateCategory |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct(NotifynderCategory $notifynderCategory) |
37
|
|
|
{ |
38
|
|
|
parent::__construct(); |
39
|
|
|
|
40
|
|
|
$this->notifynderCategory = $notifynderCategory; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Execute the console command. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function fire() |
49
|
|
|
{ |
50
|
|
|
$name = $this->argument('name'); |
51
|
|
|
$text = $this->argument('text'); |
52
|
|
|
|
53
|
|
|
$createCategory = $this->notifynderCategory->add($name, $text); |
54
|
|
|
|
55
|
|
|
if (! $createCategory) { |
56
|
|
|
$this->error('The category has been not created'); |
57
|
|
|
|
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->info("Category $createCategory->name has been created"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the console command arguments. |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
protected function getArguments() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
['name', InputArgument::REQUIRED, 'Name of the category.'], |
73
|
|
|
['text', InputArgument::REQUIRED, 'Text of the category.'], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.