1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Generator\Config; |
5
|
|
|
|
6
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Factory\NamingTrait as FactoryNamingTrait; |
7
|
|
|
use SlayerBirden\DFCodeGeneration\Generator\Controllers\NamingTrait as ControllerNamingTrait; |
8
|
|
|
|
9
|
|
|
class StandardProvider implements DataProviderInterface |
10
|
|
|
{ |
11
|
|
|
use FactoryNamingTrait, ControllerNamingTrait { |
12
|
|
|
FactoryNamingTrait::getBaseName insteadof ControllerNamingTrait; |
13
|
|
|
FactoryNamingTrait::getNs insteadof ControllerNamingTrait; |
14
|
|
|
FactoryNamingTrait::getNs as getFactoryNs; |
15
|
|
|
ControllerNamingTrait::getNs as getControllerNs; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $entityClassName; |
22
|
|
|
|
23
|
11 |
|
public function __construct(string $entityClassName) |
24
|
|
|
{ |
25
|
11 |
|
$this->entityClassName = $entityClassName; |
26
|
11 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string |
30
|
|
|
* @throws \ReflectionException |
31
|
|
|
*/ |
32
|
1 |
|
public function getRouteFactoryName(): string |
33
|
|
|
{ |
34
|
1 |
|
$baseName = $this->getBaseName($this->entityClassName); |
35
|
1 |
|
return $this->getFactoryNs($this->entityClassName) . "\\{$baseName}RoutesDelegator"; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return array |
40
|
|
|
* @throws \Doctrine\Common\Annotations\AnnotationException |
41
|
|
|
* @throws \ReflectionException |
42
|
|
|
*/ |
43
|
1 |
|
public function getInputFilterSpec(): array |
44
|
|
|
{ |
45
|
1 |
|
return (new ReflectionInputFilter($this->entityClassName))->getSpec(); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function getEntitiesSrc(): string |
49
|
|
|
{ |
50
|
|
|
// expect to have 3d part as Module |
51
|
1 |
|
$parts = explode('\\', $this->entityClassName); |
52
|
1 |
|
if (isset($parts[2])) { |
53
|
1 |
|
return sprintf('src/%s/Entities', $parts[2]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getCurrentConfig(): array |
60
|
|
|
{ |
61
|
1 |
|
$config = $this->getConfigNameSpace() . '\\' . 'ConfigProvider'; |
62
|
|
|
|
63
|
1 |
|
if (class_exists($config)) { |
64
|
|
|
return (new $config())(); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return []; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $type |
72
|
|
|
* @return string |
73
|
|
|
* @throws \ReflectionException |
74
|
|
|
*/ |
75
|
5 |
|
public function getControllerName(string $type): string |
76
|
|
|
{ |
77
|
5 |
|
$baseName = $this->getBaseName($this->entityClassName); |
78
|
5 |
|
if ($type === 'gets') { |
79
|
1 |
|
$baseName .= 's'; |
80
|
1 |
|
$type = 'get'; |
81
|
|
|
} |
82
|
|
|
|
83
|
5 |
|
return $this->getControllerNs($this->entityClassName) . '\\' . ucwords($type) . $baseName . 'Action'; |
84
|
|
|
} |
85
|
|
|
|
86
|
2 |
|
public function getConfigNameSpace(): string |
87
|
|
|
{ |
88
|
2 |
|
$parts = explode('\\', $this->entityClassName); |
89
|
2 |
|
array_splice($parts, -2); // Entities\Model |
90
|
|
|
|
91
|
2 |
|
return ltrim(implode('\\', $parts), '\\'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
* @throws \ReflectionException |
97
|
|
|
*/ |
98
|
1 |
|
public function getInputFilterName(): string |
99
|
|
|
{ |
100
|
1 |
|
return $this->getBaseName($this->entityClassName) . 'InputFilter'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|