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