| @@ 17-106 (lines=90) @@ | ||
| 14 | /** |
|
| 15 | * Class DepublishWebPageCommand |
|
| 16 | */ |
|
| 17 | class DepublishWebPageCommand extends ContainerAwareCommand |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var Bus |
|
| 21 | */ |
|
| 22 | protected $bus; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @var DepublishWebPageHandler |
|
| 26 | */ |
|
| 27 | protected $handler; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var WebPageReadService |
|
| 31 | */ |
|
| 32 | protected $service; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @var |
|
| 36 | */ |
|
| 37 | protected $commandName; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param Bus $bus |
|
| 41 | * @param DepublishWebPageHandler $handler |
|
| 42 | * @param WebPageReadService $service |
|
| 43 | * @param $commandName |
|
| 44 | */ |
|
| 45 | public function __construct( |
|
| 46 | Bus $bus, |
|
| 47 | DepublishWebPageHandler $handler, |
|
| 48 | WebPageReadService $service, |
|
| 49 | $commandName |
|
| 50 | ) { |
|
| 51 | $this->bus = $bus; |
|
| 52 | $this->handler = $handler; |
|
| 53 | $this->service = $service; |
|
| 54 | $this->commandName = $commandName; |
|
| 55 | ||
| 56 | parent::__construct(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * |
|
| 61 | */ |
|
| 62 | protected function configure() |
|
| 63 | { |
|
| 64 | $this |
|
| 65 | ->setName('black:page:depublish') |
|
| 66 | ->setDescription('Publish a new page') |
|
| 67 | ->addArgument('id', InputArgument::OPTIONAL, 'The page identifier') |
|
| 68 | ; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param InputInterface $input |
|
| 73 | * @param OutputInterface $output |
|
| 74 | */ |
|
| 75 | protected function interact(InputInterface $input, OutputInterface $output) |
|
| 76 | { |
|
| 77 | $dialog = $this->getHelperSet()->get('dialog'); |
|
| 78 | ||
| 79 | if (!$input->getArgument('id')) { |
|
| 80 | $id = $dialog->askAndValidate( |
|
| 81 | $output, |
|
| 82 | 'Please give an id:', |
|
| 83 | function ($id) { |
|
| 84 | if (empty($id)) { |
|
| 85 | throw new \InvalidArgumentException('Id cannot be empty!'); |
|
| 86 | } |
|
| 87 | ||
| 88 | return $id; |
|
| 89 | } |
|
| 90 | ); |
|
| 91 | ||
| 92 | $input->setArgument('id', $id); |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 97 | { |
|
| 98 | $pageId = new WebPageId($input->getArgument('id')); |
|
| 99 | $page = $this->service->read($pageId); |
|
| 100 | ||
| 101 | if ($page) { |
|
| 102 | $this->bus->register($this->commandName, $this->handler); |
|
| 103 | $this->bus->handle(new $this->commandName($page)); |
|
| 104 | } |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||
| @@ 17-106 (lines=90) @@ | ||
| 14 | /** |
|
| 15 | * Class PublishWebPageCommand |
|
| 16 | */ |
|
| 17 | class PublishWebPageCommand extends ContainerAwareCommand |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var Bus |
|
| 21 | */ |
|
| 22 | protected $bus; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @var PublishWebPageHandler |
|
| 26 | */ |
|
| 27 | protected $handler; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var WebPageReadService |
|
| 31 | */ |
|
| 32 | protected $service; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @var |
|
| 36 | */ |
|
| 37 | protected $commandName; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param Bus $bus |
|
| 41 | * @param PublishWebPageHandler $handler |
|
| 42 | * @param WebPageReadService $service |
|
| 43 | * @param $commandName |
|
| 44 | */ |
|
| 45 | public function __construct( |
|
| 46 | Bus $bus, |
|
| 47 | PublishWebPageHandler $handler, |
|
| 48 | WebPageReadService $service, |
|
| 49 | $commandName |
|
| 50 | ) { |
|
| 51 | $this->bus = $bus; |
|
| 52 | $this->handler = $handler; |
|
| 53 | $this->service = $service; |
|
| 54 | $this->commandName = $commandName; |
|
| 55 | ||
| 56 | parent::__construct(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * |
|
| 61 | */ |
|
| 62 | protected function configure() |
|
| 63 | { |
|
| 64 | $this |
|
| 65 | ->setName('black:page:publish') |
|
| 66 | ->setDescription('Publish a new page') |
|
| 67 | ->addArgument('id', InputArgument::OPTIONAL, 'The page identifier') |
|
| 68 | ; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param InputInterface $input |
|
| 73 | * @param OutputInterface $output |
|
| 74 | */ |
|
| 75 | protected function interact(InputInterface $input, OutputInterface $output) |
|
| 76 | { |
|
| 77 | $dialog = $this->getHelperSet()->get('dialog'); |
|
| 78 | ||
| 79 | if (!$input->getArgument('id')) { |
|
| 80 | $id = $dialog->askAndValidate( |
|
| 81 | $output, |
|
| 82 | 'Please give an id:', |
|
| 83 | function ($id) { |
|
| 84 | if (empty($id)) { |
|
| 85 | throw new \InvalidArgumentException('Id cannot be empty!'); |
|
| 86 | } |
|
| 87 | ||
| 88 | return $id; |
|
| 89 | } |
|
| 90 | ); |
|
| 91 | ||
| 92 | $input->setArgument('id', $id); |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 97 | { |
|
| 98 | $pageId = new WebPageId($input->getArgument('id')); |
|
| 99 | $page = $this->service->read($pageId); |
|
| 100 | ||
| 101 | if ($page) { |
|
| 102 | $this->bus->register($this->commandName, $this->handler); |
|
| 103 | $this->bus->handle(new $this->commandName($page)); |
|
| 104 | } |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||
| @@ 17-106 (lines=90) @@ | ||
| 14 | /** |
|
| 15 | * Class RemoveWebPageCommand |
|
| 16 | */ |
|
| 17 | class RemoveWebPageCommand extends ContainerAwareCommand |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var Bus |
|
| 21 | */ |
|
| 22 | protected $bus; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @var RemoveWebPageHandler |
|
| 26 | */ |
|
| 27 | protected $handler; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var WebPageReadService |
|
| 31 | */ |
|
| 32 | protected $service; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @var |
|
| 36 | */ |
|
| 37 | protected $commandName; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param Bus $bus |
|
| 41 | * @param RemoveWebPageHandler $handler |
|
| 42 | * @param WebPageReadService $service |
|
| 43 | * @param $commandName |
|
| 44 | */ |
|
| 45 | public function __construct( |
|
| 46 | Bus $bus, |
|
| 47 | RemoveWebPageHandler $handler, |
|
| 48 | WebPageReadService $service, |
|
| 49 | $commandName |
|
| 50 | ) { |
|
| 51 | $this->bus = $bus; |
|
| 52 | $this->handler = $handler; |
|
| 53 | $this->service = $service; |
|
| 54 | $this->commandName = $commandName; |
|
| 55 | ||
| 56 | parent::__construct(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * |
|
| 61 | */ |
|
| 62 | protected function configure() |
|
| 63 | { |
|
| 64 | $this |
|
| 65 | ->setName('black:page:remove') |
|
| 66 | ->setDescription('Remove a new page') |
|
| 67 | ->addArgument('id', InputArgument::OPTIONAL, 'The page identifier') |
|
| 68 | ; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param InputInterface $input |
|
| 73 | * @param OutputInterface $output |
|
| 74 | */ |
|
| 75 | protected function interact(InputInterface $input, OutputInterface $output) |
|
| 76 | { |
|
| 77 | $dialog = $this->getHelperSet()->get('dialog'); |
|
| 78 | ||
| 79 | if (!$input->getArgument('id')) { |
|
| 80 | $id = $dialog->askAndValidate( |
|
| 81 | $output, |
|
| 82 | 'Please give an id:', |
|
| 83 | function ($id) { |
|
| 84 | if (empty($id)) { |
|
| 85 | throw new \InvalidArgumentException('Id cannot be empty!'); |
|
| 86 | } |
|
| 87 | ||
| 88 | return $id; |
|
| 89 | } |
|
| 90 | ); |
|
| 91 | ||
| 92 | $input->setArgument('id', $id); |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 97 | { |
|
| 98 | $pageId = new WebPageId($input->getArgument('id')); |
|
| 99 | $page = $this->service->read($pageId); |
|
| 100 | ||
| 101 | if ($page) { |
|
| 102 | $this->bus->register($this->commandName, $this->handler); |
|
| 103 | $this->bus->handle(new $this->commandName($page)); |
|
| 104 | } |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||