-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathConstant.php
60 lines (46 loc) · 1.32 KB
/
Constant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\SchemaGenerator\Model;
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\Constant as NetteConstant;
abstract class Constant
{
private string $name;
/** @var array<string> */
private array $annotations = [];
public function __construct(string $name)
{
$this->name = $name;
}
public function name(): string
{
return $this->name;
}
abstract public function value(): string;
abstract public function comment(): string;
public function addAnnotation(string $annotation): self
{
if (!\in_array($annotation, $this->annotations, true)) {
$this->annotations[] = $annotation;
}
return $this;
}
public function toNetteConstant(): NetteConstant
{
$constant = (new NetteConstant($this->name))
->setValue($this->value())
->setVisibility(ClassType::VISIBILITY_PUBLIC);
foreach ($this->annotations as $annotation) {
$constant->addComment($annotation);
}
return $constant;
}
}