|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Spiral Framework. |
|
4
|
|
|
* |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* @author Valentin V (Vvval) |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Cycle\ORM\Promise; |
|
11
|
|
|
|
|
12
|
|
|
use Cycle\ORM\ORMInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class Schema |
|
15
|
|
|
{ |
|
16
|
|
|
public const RESOLVER_PROPERTY = '__resolver'; |
|
17
|
|
|
public const UNSET_PROPERTIES_CONST = '__UNSET_PROPERTIES'; |
|
18
|
|
|
public const INIT_METHOD = '__init'; |
|
19
|
|
|
|
|
20
|
|
|
public const INIT_DEPENDENCIES = [ |
|
21
|
|
|
'orm' => ORMInterface::class, |
|
22
|
|
|
'role' => 'string', |
|
23
|
|
|
'scope' => 'array' |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
private const USE_STMTS = [ |
|
27
|
|
|
PromiseInterface::class, |
|
28
|
|
|
Resolver::class, |
|
29
|
|
|
ProxyFactoryException::class, |
|
30
|
|
|
ORMInterface::class |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** @var ConflictResolver */ |
|
34
|
|
|
private $resolver; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(ConflictResolver $resolver) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->resolver = $resolver; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function useStmts(Declaration\DeclarationInterface $class, Declaration\DeclarationInterface $parent): array |
|
42
|
|
|
{ |
|
43
|
|
|
$useStmts = self::USE_STMTS; |
|
44
|
|
|
if ($class->getNamespaceName() !== $parent->getNamespaceName()) { |
|
45
|
|
|
$useStmts[] = $parent->getFullName(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $useStmts; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function initMethodName(Declaration\Structure $structure): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->resolver->resolve($structure->methodNames(), Schema::INIT_METHOD)->fullName(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function resolverPropertyName(Declaration\Structure $structure): string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->resolver->resolve($structure->properties, Schema::RESOLVER_PROPERTY)->fullName(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function unsetPropertiesConstName(Declaration\Structure $structure): string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->resolver->resolve($structure->constants, Schema::UNSET_PROPERTIES_CONST)->fullName('_'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function propertyType(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return Utils::shortName(Resolver::class); |
|
69
|
|
|
} |
|
70
|
|
|
} |