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