1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Plaisio\Console\Kernel\Command; |
5
|
|
|
|
6
|
|
|
use Noodlehaus\Config; |
7
|
|
|
use Plaisio\Console\Command\PlaisioCommand; |
8
|
|
|
use Plaisio\Console\Helper\PlaisioXmlPathHelper; |
9
|
|
|
use Plaisio\Console\Helper\TwoPhaseWrite; |
10
|
|
|
use Plaisio\Console\Kernel\Helper\PlaisioXmlQueryHelper; |
11
|
|
|
use Plaisio\PlaisioKernel; |
12
|
|
|
use SetBased\Config\TypedConfig; |
13
|
|
|
use SetBased\Helper\Cast; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Command for setting the type of the DataLayer in the kernel. |
20
|
|
|
*/ |
21
|
|
|
class DataLayerTypeCommand extends PlaisioCommand |
22
|
|
|
{ |
23
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
24
|
|
|
/** |
25
|
|
|
* The declaration of the DataLayer. |
26
|
|
|
*/ |
27
|
|
|
const PUBLIC_STATIC_DL = '/(?P<property>.*@property-read) (?P<class>.+) (?P<dl>\$DL) (?P<comment>.*)$/'; |
28
|
|
|
|
29
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
30
|
|
|
/** |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
$this->setName('plaisio:kernel-data-layer-type') |
36
|
|
|
->setDescription(sprintf('Sets the type of the DataLayer in %s', PlaisioKernel::class)) |
37
|
|
|
->addArgument('class', InputArgument::OPTIONAL, 'The class of the DataLayer'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
45
|
|
|
{ |
46
|
|
|
$this->io->title('Plaisio: DataLayer Type Annotation'); |
47
|
|
|
|
48
|
|
|
$wrapperClass = Cast::toOptString($input->getArgument('class')); |
49
|
|
|
if ($wrapperClass===null) |
50
|
|
|
{ |
51
|
|
|
$configFilename = $this->phpStratumConfigFilename(); |
52
|
|
|
$wrapperClass = $this->wrapperClass($configFilename); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$configPath = PlaisioXmlPathHelper::vendorDir().DIRECTORY_SEPARATOR.'plaisio/kernel/plaisio-kernel.xml'; |
56
|
|
|
$config = new PlaisioXmlQueryHelper($configPath); |
57
|
|
|
$xml = $config->updateDataLayerType($wrapperClass); |
58
|
|
|
|
59
|
|
|
$helper = new TwoPhaseWrite($this->io); |
60
|
|
|
$helper->write($configPath, $xml); |
61
|
|
|
|
62
|
|
|
return 0; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
66
|
|
|
/** |
67
|
|
|
* Returns the name of the PhpStratum configuration file. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
private function phpStratumConfigFilename(): string |
72
|
|
|
{ |
73
|
|
|
$path1 = PlaisioXmlPathHelper::plaisioXmlPath('stratum'); |
74
|
|
|
$helper = new PlaisioXmlQueryHelper($path1); |
75
|
|
|
|
76
|
|
|
$path2 = $helper->queryPhpStratumConfigFilename(); |
77
|
|
|
|
78
|
|
|
return PlaisioXmlPathHelper::relativePath(dirname($path1).DIRECTORY_SEPARATOR.$path2); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
82
|
|
|
/** |
83
|
|
|
* Extracts the wrapper class name from the PhpStratum configuration file. |
84
|
|
|
* |
85
|
|
|
* @param string $configFilename The name of the PhpStratum configuration file. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
private function wrapperClass(string $configFilename): string |
90
|
|
|
{ |
91
|
|
|
$config = new TypedConfig(new Config($configFilename)); |
92
|
|
|
|
93
|
|
|
return $config->getManString('wrapper.wrapper_class'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
100
|
|
|
|