|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the SexyField package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dion Snoeijen <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare (strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Tardigrades\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
20
|
|
|
use Tardigrades\SectionField\Service\SectionManagerInterface; |
|
21
|
|
|
use Tardigrades\SectionField\ValueObject\SectionConfig; |
|
22
|
|
|
|
|
23
|
|
|
class CreateSectionCommand extends SectionCommand |
|
24
|
|
|
{ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
SectionManagerInterface $sectionManager |
|
27
|
|
|
) { |
|
28
|
|
|
parent::__construct($sectionManager, 'sf:create-section'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function configure(): void |
|
32
|
|
|
{ |
|
33
|
|
|
// @codingStandardsIgnoreStart |
|
34
|
|
|
$this |
|
35
|
|
|
->setDescription('Creates a new section.') |
|
36
|
|
|
->setHelp('This command allows you to create a section based on a yml section configuration. Pass along the path to a section configuration yml. Something like: section/blog.yml') |
|
37
|
|
|
->addArgument('config', InputArgument::REQUIRED, 'The section configuration yml') |
|
38
|
|
|
; |
|
39
|
|
|
// @codingStandardsIgnoreEnd |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
|
43
|
|
|
{ |
|
44
|
|
|
$config = $input->getArgument('config'); |
|
45
|
|
|
|
|
46
|
|
|
try { |
|
47
|
|
|
if (file_exists($config)) { |
|
48
|
|
|
$parsed = Yaml::parse(file_get_contents($config)); |
|
49
|
|
|
if (is_array($parsed)) { |
|
50
|
|
|
$sectionConfig = SectionConfig::fromArray($parsed); |
|
51
|
|
|
$this->sectionManager->createByConfig($sectionConfig); |
|
52
|
|
|
$output->writeln('<info>Section created!</info>'); |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
throw new \Exception('No valid config found.'); |
|
57
|
|
|
} catch (\Exception $exception) { |
|
58
|
|
|
$output->writeln("<error>Invalid configuration file. {$exception->getMessage()}</error>"); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|