1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* DataBagAnnotation.php |
5
|
|
|
* |
6
|
|
|
* Jaxon annotation for data bags. |
7
|
|
|
* |
8
|
|
|
* @package jaxon-annotations |
9
|
|
|
* @copyright 2022 Thierry Feuzeu <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
11
|
|
|
* @link https://github.com/jaxon-php/jaxon-annotations |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jaxon\Annotations\Annotation; |
15
|
|
|
|
16
|
|
|
use mindplay\annotations\AnnotationException; |
17
|
|
|
|
18
|
|
|
use function count; |
19
|
|
|
use function is_array; |
20
|
|
|
use function is_string; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Specifies attributes to inject into a callable object. |
24
|
|
|
* |
25
|
|
|
* @usage('class' => true, 'method'=>true, 'multiple'=>true, 'inherited'=>true) |
26
|
|
|
*/ |
27
|
|
|
class ContainerAnnotation extends AbstractAnnotation |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The attribute name |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $sAttr = ''; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The attribute class |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $sClass = ''; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
* @throws AnnotationException |
46
|
|
|
*/ |
47
|
|
|
public function initAnnotation(array $properties) |
48
|
|
|
{ |
49
|
|
|
if(count($properties) != 2 || |
50
|
|
|
!isset($properties['attr']) || !is_string($properties['attr']) || |
51
|
|
|
!isset($properties['class']) || !is_string($properties['class'])) |
52
|
|
|
{ |
53
|
|
|
throw new AnnotationException('The @di annotation requires a property "attr" of type string ' . |
54
|
|
|
'and a property "class" of type string'); |
55
|
|
|
} |
56
|
|
|
$this->sAttr = $properties['attr']; |
57
|
|
|
$this->sClass = $properties['class']; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
|
public function getName(): string |
64
|
|
|
{ |
65
|
|
|
return '__di'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritDoc |
70
|
|
|
*/ |
71
|
|
|
public function getValue() |
72
|
|
|
{ |
73
|
|
|
if(is_array($this->xPrevValue)) |
74
|
|
|
{ |
75
|
|
|
$this->xPrevValue[$this->sAttr] = $this->sClass; // Append the current value to the array |
76
|
|
|
return $this->xPrevValue; |
77
|
|
|
} |
78
|
|
|
return [$this->sAttr => $this->sClass]; // Return the current value in an array |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|