1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Reflection\Definition\Dependent; |
11
|
|
|
|
12
|
|
|
use Railt\Reflection\Contracts\Definition\Dependent\DirectiveLocation as DirectiveLocationInterface; |
13
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
14
|
|
|
use Railt\Reflection\Contracts\Type as TypeInterface; |
15
|
|
|
use Railt\Reflection\Document; |
16
|
|
|
use Railt\Reflection\Type; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class DirectiveLocation |
20
|
|
|
*/ |
21
|
|
|
class DirectiveLocation extends AbstractDependentTypeDefinition implements DirectiveLocationInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* DirectiveLocation constructor. |
25
|
|
|
* @param TypeDefinition $parent |
26
|
|
|
* @param Document $document |
27
|
|
|
* @param string $name |
28
|
|
|
*/ |
29
|
9 |
|
public function __construct(TypeDefinition $parent, Document $document, string $name) |
30
|
|
|
{ |
31
|
9 |
|
\assert(\in_array($name, \array_merge(static::EXECUTABLE_LOCATIONS, static::SDL_LOCATIONS), true)); |
32
|
|
|
|
33
|
9 |
|
parent::__construct($parent, $document, $name); |
34
|
9 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function isExecutable(): bool |
40
|
|
|
{ |
41
|
|
|
return \in_array($this->getName(), static::EXECUTABLE_LOCATIONS, true); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function isPrivate(): bool |
48
|
|
|
{ |
49
|
|
|
return \in_array($this->getName(), static::SDL_LOCATIONS, true); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param TypeInterface $type |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function isAllowedFor(TypeInterface $type): bool |
57
|
|
|
{ |
58
|
|
|
$location = static::LOCATION_TO_TYPES[$this->getName()] ?? Type::ANY; |
59
|
|
|
|
60
|
|
|
return $type->instanceOf(Type::of($location)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return TypeInterface |
65
|
|
|
*/ |
66
|
|
|
public static function getType(): TypeInterface |
67
|
|
|
{ |
68
|
|
|
return Type::of(Type::DIRECTIVE_LOCATION); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|