-
Notifications
You must be signed in to change notification settings - Fork 4
/
NewsCreate.php
46 lines (37 loc) · 1.72 KB
/
NewsCreate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace BDC\SimpleNews\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use BDC\SimpleNews\Helper\News;
class NewsCreate extends Command {
protected $newsHelper;
public function __construct(News $newsHelper) {
$this->newsHelper = $newsHelper;
parent::__construct();
}
protected function configure(){
$this->setName('bdcrops:news:create')
->setDescription('Create New News')
->setDefinition($this->getOptionsList());
}
protected function execute(InputInterface $input, OutputInterface $output){
$output->writeln('<info>Creating new news...</info>');
$this->newsHelper->setData($input);
$this->newsHelper->execute();
$output->writeln('');
$output->writeln('<info>News created with the following data:</info>');
$output->writeln('<comment>News ID: ' . $this->newsHelper->getNewsId());
$output->writeln('<comment>Title: ' . $input->getOption(News::KEY_TITLE));
$output->writeln('<comment>Summary: ' . $input->getOption(News::KEY_SUMMARY));
$output->writeln('<comment>Description: ' . $input->getOption(News::KEY_DESC));
}
protected function getOptionsList(){
return [
new InputOption(News::KEY_TITLE, null, InputOption::VALUE_REQUIRED, '(Required) News Title'),
new InputOption(News::KEY_SUMMARY, null, InputOption::VALUE_REQUIRED, '(Required) News Summary'),
new InputOption(News::KEY_DESC, null, InputOption::VALUE_REQUIRED, '(Required) News Description'),
];
}
}