|
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
|
|
|
use mindplay\annotations\AnnotationFile; |
|
18
|
|
|
use mindplay\annotations\IAnnotationFileAware; |
|
19
|
|
|
|
|
20
|
|
|
use function count; |
|
21
|
|
|
use function is_array; |
|
22
|
|
|
use function is_string; |
|
23
|
|
|
use function ltrim; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Specifies attributes to inject into a callable object. |
|
27
|
|
|
* |
|
28
|
|
|
* @usage('class' => true, 'method'=>true, 'multiple'=>true, 'inherited'=>true) |
|
29
|
|
|
*/ |
|
30
|
|
|
class ContainerAnnotation extends AbstractAnnotation implements IAnnotationFileAware |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* The attribute name |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $sAttr = ''; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The attribute class |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $sClass = ''; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var AnnotationFile |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $xClassFile; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritDoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setAnnotationFile(AnnotationFile $file) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->xClassFile = $file; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @inheritDoc |
|
61
|
|
|
* @throws AnnotationException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function initAnnotation(array $properties) |
|
64
|
|
|
{ |
|
65
|
|
|
if(count($properties) != 2 || |
|
66
|
|
|
!isset($properties['attr']) || !is_string($properties['attr']) || |
|
67
|
|
|
!isset($properties['class']) || !is_string($properties['class'])) |
|
68
|
|
|
{ |
|
69
|
|
|
throw new AnnotationException('The @di annotation requires a property "attr" of type string ' . |
|
70
|
|
|
'and a property "class" of type string'); |
|
71
|
|
|
} |
|
72
|
|
|
$this->sAttr = $properties['attr']; |
|
73
|
|
|
$this->sClass = ltrim($this->xClassFile->resolveType($properties['class']), '\\'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @inheritDoc |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getName(): string |
|
80
|
|
|
{ |
|
81
|
|
|
return '__di'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @inheritDoc |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getValue() |
|
88
|
|
|
{ |
|
89
|
|
|
if(is_array($this->xPrevValue)) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->xPrevValue[$this->sAttr] = $this->sClass; // Append the current value to the array |
|
92
|
|
|
return $this->xPrevValue; |
|
93
|
|
|
} |
|
94
|
|
|
return [$this->sAttr => $this->sClass]; // Return the current value in an array |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|