|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Cubiche package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Cubiche |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Cubiche\Infrastructure\Identity\Doctrine\ODM\MongoDB\Metadata\Driver; |
|
12
|
|
|
|
|
13
|
|
|
use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Metadata\Exception\MappingException; |
|
14
|
|
|
use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Metadata\Driver\XmlDriver as BaseXmlDriver; |
|
15
|
|
|
use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Metadata\PropertyMetadata; |
|
16
|
|
|
use Cubiche\Core\Metadata\MergeableClassMetadata; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* XmlDriver class. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class XmlDriver extends BaseXmlDriver |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function addMetadataFor(\SimpleXMLElement $xmlRoot, MergeableClassMetadata $classMetadata) |
|
29
|
|
|
{ |
|
30
|
|
|
foreach ($xmlRoot->xpath('//cubiche:id') as $item) { |
|
31
|
|
|
// get the field tag |
|
32
|
|
|
$field = $item->xpath('..')[0]; |
|
33
|
|
|
$fieldMapping = $this->getMappingAttributes($field); |
|
34
|
|
|
$fieldName = $fieldMapping['name']; |
|
35
|
|
|
|
|
36
|
|
|
$itemMapping = $this->getMappingAttributes($item); |
|
37
|
|
|
foreach ($item->attributes() as $key => $value) { |
|
38
|
|
|
$itemMapping[$key] = (string) $value; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!isset($itemMapping['type'])) { |
|
42
|
|
|
throw MappingException::inField( |
|
43
|
|
|
'The cubiche:id definition should have a "type" value', |
|
44
|
|
|
$classMetadata->name, |
|
45
|
|
|
$fieldName |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$idType = $itemMapping['type']; |
|
50
|
|
|
|
|
51
|
|
|
if ($field->getName() == 'field') { |
|
52
|
|
|
if (!isset($fieldMapping['type']) || |
|
53
|
|
|
(isset($fieldMapping['type']) && $fieldMapping['type'] !== 'Identifier') |
|
54
|
|
|
) { |
|
55
|
|
|
throw MappingException::inField( |
|
56
|
|
|
'The cubiche:id configuration is only for id fields', |
|
57
|
|
|
$classMetadata->name, |
|
58
|
|
|
$fieldName |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$propertyMetadata = new PropertyMetadata($classMetadata->name, $fieldName, 'id'); |
|
63
|
|
|
$propertyMetadata->setType($idType); |
|
64
|
|
|
|
|
65
|
|
|
$classMetadata->addPropertyMetadata($propertyMetadata); |
|
66
|
|
|
} else { |
|
67
|
|
|
throw MappingException::inField( |
|
68
|
|
|
'The cubiche:id configuration is only for id fields', |
|
69
|
|
|
$classMetadata->name, |
|
70
|
|
|
$fieldName |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|