|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Component\DocumentManager\Metadata; |
|
13
|
|
|
|
|
14
|
|
|
use PHPCR\NodeInterface; |
|
15
|
|
|
use Sulu\Component\DocumentManager\Document\UnknownDocument; |
|
16
|
|
|
use Sulu\Component\DocumentManager\DocumentStrategyInterface; |
|
17
|
|
|
use Sulu\Component\DocumentManager\Metadata; |
|
18
|
|
|
use Sulu\Component\DocumentManager\MetadataFactoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class fully implements the MetadataFactoryInterface by composing |
|
22
|
|
|
* the "base" metadata factory and the document strategy, which depends also |
|
23
|
|
|
* upon the base metadata factory. |
|
24
|
|
|
*/ |
|
25
|
|
|
class MetadataFactory implements MetadataFactoryInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var MetadataFactoryInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $metadataFactory; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var DocumentStrategyInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $strategy; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param MetadataFactoryInterface $metadataFactory |
|
39
|
|
|
* @param DocumentStrategyInterface $strategy |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
MetadataFactoryInterface $metadataFactory, |
|
43
|
|
|
DocumentStrategyInterface $strategy |
|
44
|
|
|
) { |
|
45
|
|
|
$this->metadataFactory = $metadataFactory; |
|
46
|
|
|
$this->strategy = $strategy; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getMetadataForAlias($alias) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->metadataFactory->getMetadataForAlias($alias); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getMetadataForPhpcrType($phpcrType) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->metadataFactory->getMetadataForPhpcrType($phpcrType); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function hasMetadataForPhpcrType($phpcrType) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->metadataFactory->hasMetadataForPhpcrType($phpcrType); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getMetadataForClass($class) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->metadataFactory->getMetadataForClass($class); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritdoc} |
|
83
|
|
|
*/ |
|
84
|
|
|
public function hasMetadataForClass($class) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->metadataFactory->hasMetadataForClass($class); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritdoc} |
|
91
|
|
|
*/ |
|
92
|
|
|
public function hasAlias($alias) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->metadataFactory->hasAlias($alias); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getAliases() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->metadataFactory->getAliases(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getMetadataForPhpcrNode(NodeInterface $node) |
|
109
|
|
|
{ |
|
110
|
|
|
$metadata = $this->strategy->resolveMetadataForNode($node); |
|
111
|
|
|
|
|
112
|
|
|
if (null !== $metadata) { |
|
113
|
|
|
return $metadata; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $this->getUnknownMetadata(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return Metadata |
|
121
|
|
|
*/ |
|
122
|
|
|
private function getUnknownMetadata() |
|
123
|
|
|
{ |
|
124
|
|
|
$metadata = new Metadata(); |
|
125
|
|
|
$metadata->setAlias(null); |
|
126
|
|
|
$metadata->setPhpcrType(null); |
|
127
|
|
|
$metadata->setClass(UnknownDocument::class); |
|
128
|
|
|
|
|
129
|
|
|
return $metadata; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|