forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAttributesHydratorTrait.php
More file actions
73 lines (62 loc) · 2.25 KB
/
AttributesHydratorTrait.php
File metadata and controls
73 lines (62 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Annotation;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\Common\Inflector\Inflector;
/**
* Hydrates attributes from annotation's parameters.
*
* @internal
*
* @author Baptiste Meyer <baptiste.meyer@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
trait AttributesHydratorTrait
{
/**
* @var array
*/
public $attributes = null;
/**
* @throws InvalidArgumentException
*/
private function hydrateAttributes(array $values): void
{
if (isset($values['attributes'])) {
$this->attributes = $values['attributes'];
unset($values['attributes']);
}
if (\array_key_exists('accessControl', $values)) {
$values['security'] = $values['accessControl'];
@trigger_error('Attribute "accessControl" is deprecated in annotation since API Platform 2.5, prefer using "security" attribute instead', E_USER_DEPRECATED);
unset($values['accessControl']);
}
if (\array_key_exists('accessControlMessage', $values)) {
$values['securityMessage'] = $values['accessControlMessage'];
@trigger_error('Attribute "accessControlMessage" is deprecated in annotation since API Platform 2.5, prefer using "securityMessage" attribute instead', E_USER_DEPRECATED);
unset($values['accessControlMessage']);
}
foreach ($values as $key => $value) {
$key = (string) $key;
if (!property_exists($this, $key)) {
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class));
}
if ((new \ReflectionProperty($this, $key))->isPublic()) {
$this->{$key} = $value;
continue;
}
if (!\is_array($this->attributes)) {
$this->attributes = [];
}
$this->attributes += [Inflector::tableize($key) => $value];
}
}
}