1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the reva2/jsonapi. |
4
|
|
|
* |
5
|
|
|
* (c) OrbitScripts LLC <[email protected]> |
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
|
|
|
|
12
|
|
|
namespace Reva2\JsonApi\Decoders\Mapping; |
13
|
|
|
|
14
|
|
|
use Reva2\JsonApi\Contracts\Decoders\Mapping\ObjectMetadataInterface; |
15
|
|
|
use Reva2\JsonApi\Contracts\Decoders\Mapping\PropertyMetadataInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* ObjectMetadata |
19
|
|
|
* |
20
|
|
|
* @package Reva2\JsonApi\Decoders\Mapping |
21
|
|
|
* @author Sergey Revenko <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ObjectMetadata extends ClassMetadata implements ObjectMetadataInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var PropertyMetadataInterface[] |
27
|
|
|
*/ |
28
|
|
|
public $properties = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns object properties metadata |
32
|
|
|
* |
33
|
|
|
* @return PropertyMetadataInterface[] |
34
|
|
|
*/ |
35
|
1 |
|
public function getProperties() |
36
|
|
|
{ |
37
|
1 |
|
return $this->properties; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Adds property metadata |
42
|
|
|
* |
43
|
|
|
* @param PropertyMetadataInterface $metadata |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
1 |
|
public function addProperty(PropertyMetadataInterface $metadata) |
47
|
|
|
{ |
48
|
1 |
|
$this->properties[$metadata->getPropertyName()] = $metadata; |
49
|
|
|
|
50
|
1 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
1 |
|
public function mergeMetadata($metadata = null) |
57
|
|
|
{ |
58
|
1 |
|
if (null === $metadata) { |
59
|
|
|
if (!$metadata instanceof ObjectMetadataInterface) { |
60
|
|
|
/* @var $metadata \Reva2\JsonApi\Contracts\Decoders\Mapping\GenericMetadataInterface */ |
61
|
|
|
|
62
|
|
|
throw new \RuntimeException(sprintf( |
63
|
|
|
"Failed to merge metadata from parent class %s", |
64
|
|
|
$metadata->getClassName() |
65
|
|
|
)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->properties = array_merge($this->properties, $metadata->getProperties()); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
} |