|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jellyfish\Transfer\Definition; |
|
4
|
|
|
|
|
5
|
|
|
class ClassDefinition implements ClassDefinitionInterface |
|
6
|
|
|
{ |
|
7
|
|
|
public const NAMESPACE_PREFIX = 'Generated\\Transfer'; |
|
8
|
|
|
public const NAMESPACE_SEPARATOR = '\\'; |
|
9
|
|
|
public const FACTORY_NAME_SUFFIX = 'Factory'; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $name; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string|null |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $namespace; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[] |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $properties; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getId(): string |
|
30
|
|
|
{ |
|
31
|
|
|
$pattern = '/(?<=\\w)(?=[A-Z])/'; |
|
32
|
|
|
$replacement = '_$1'; |
|
33
|
|
|
$id = \str_replace('\\', '', static::NAMESPACE_PREFIX); |
|
34
|
|
|
|
|
35
|
|
|
if ($this->namespace !== null) { |
|
36
|
|
|
$id .= $this->namespace; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$id .= $this->name; |
|
40
|
|
|
$id = \preg_replace($pattern, $replacement, $id); |
|
41
|
|
|
|
|
42
|
|
|
return \strtolower($id); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getName(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->name; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $name |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setName(string $name): ClassDefinitionInterface |
|
59
|
|
|
{ |
|
60
|
|
|
$this->name = $name; |
|
61
|
|
|
|
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string|null |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getNamespace(): ?string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->namespace; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string|null $namespace |
|
75
|
|
|
* |
|
76
|
|
|
* @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setNamespace(?string $namespace): ClassDefinitionInterface |
|
79
|
|
|
{ |
|
80
|
|
|
$this->namespace = $namespace; |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[] |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getProperties(): array |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->properties; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[] $properties |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setProperties(array $properties): ClassDefinitionInterface |
|
99
|
|
|
{ |
|
100
|
|
|
$this->properties = $properties; |
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|