|
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 Tardigrades\SectionField\Service\FieldTypeManagerInterface; |
|
20
|
|
|
use Tardigrades\SectionField\Service\FieldTypeNotFoundException; |
|
21
|
|
|
use Tardigrades\SectionField\ValueObject\FullyQualifiedClassName; |
|
22
|
|
|
|
|
23
|
|
|
class InstallFieldTypeCommand extends FieldTypeCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var FieldTypeManagerInterface */ |
|
26
|
|
|
private $fieldTypeManager; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
FieldTypeManagerInterface $fieldTypeManager |
|
30
|
|
|
) { |
|
31
|
|
|
$this->fieldTypeManager = $fieldTypeManager; |
|
32
|
|
|
parent::__construct('sf:install-field-type'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function configure() |
|
36
|
|
|
{ |
|
37
|
|
|
$this |
|
38
|
|
|
->setDescription('Install a field type. Escape the backslash! Like so: This\\\Is\\\ClassName') |
|
39
|
|
|
->setHelp('This command installs a field type, just give the namespace where to find the field.') |
|
40
|
|
|
->addArgument('namespace', InputArgument::REQUIRED, 'Field type namespace') |
|
41
|
|
|
; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
|
|
$namespace = $input->getArgument('namespace'); |
|
47
|
|
|
$fullyQualifiedClassName = FullyQualifiedClassName::fromString($namespace); |
|
48
|
|
|
|
|
49
|
|
|
try { |
|
50
|
|
|
$this->fieldTypeManager->readByFullyQualifiedClassName($fullyQualifiedClassName); |
|
51
|
|
|
$output->writeln('<info>FieldType already installed</info>'); |
|
52
|
|
|
} catch (FieldTypeNotFoundException $exception) { |
|
53
|
|
|
$fieldType = $this->fieldTypeManager->createWithFullyQualifiedClassName($fullyQualifiedClassName); |
|
54
|
|
|
$this->renderTable($output, [$fieldType], 'FieldTypeInterface installed!'); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|