1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (c) 2011-2015, Celestino Diaz <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22
|
|
|
* THE SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Brickoo\Component\Annotation; |
26
|
|
|
|
27
|
|
|
use Brickoo\Component\IO\Printing\OutputBufferedPrinter; |
28
|
|
|
use Brickoo\Component\IO\Printing\PlainTextPrinter; |
29
|
|
|
use Brickoo\Component\IO\Printing\Printable; |
30
|
|
|
use Brickoo\Component\IO\Printing\Printer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* AnnotationReaderResultPrinter |
34
|
|
|
* |
35
|
|
|
* Implementation of an annotation reader result printer. |
36
|
|
|
* @author Celestino Diaz <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class AnnotationReaderResultPrinter implements Printable { |
39
|
|
|
|
40
|
|
|
/** @var \Brickoo\Component\IO\Printing\Printer */ |
41
|
|
|
private $printer; |
42
|
|
|
|
43
|
|
|
/** @var \Brickoo\Component\Annotation\AnnotationReaderResult */ |
44
|
|
|
private $annotationReaderResult; |
45
|
|
|
|
46
|
|
|
/** @param AnnotationReaderResult $annotationReaderResult */ |
47
|
1 |
|
public function __construct(AnnotationReaderResult $annotationReaderResult) { |
48
|
1 |
|
$this->annotationReaderResult = $annotationReaderResult; |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** {@inheritdoc} */ |
52
|
1 |
|
public function setPrinter(Printer $printer) { |
53
|
1 |
|
$this->printer = $printer; |
54
|
1 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** {@inheritdoc} */ |
58
|
2 |
|
public function getPrinter() { |
59
|
2 |
|
if (!$this->printer instanceof Printer) { |
60
|
1 |
|
$this->printer = new PlainTextPrinter(new OutputBufferedPrinter()); |
61
|
1 |
|
} |
62
|
2 |
|
return $this->printer; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** {@inheritdoc} */ |
66
|
1 |
|
public function runPrinter() { |
67
|
|
|
$targets = [ |
68
|
1 |
|
Annotation::TARGET_CLASS => "Class", |
69
|
1 |
|
Annotation::TARGET_METHOD => "Method", |
70
|
1 |
|
Annotation::TARGET_PROPERTY => "Property" |
71
|
1 |
|
]; |
72
|
|
|
|
73
|
1 |
|
foreach ($targets as $targetIdentifier => $targetName) { |
74
|
1 |
|
$this->printAnnotationsByTarget( |
75
|
1 |
|
$targetName, |
76
|
1 |
|
$this->annotationReaderResult->getAnnotationsByTarget($targetIdentifier) |
77
|
1 |
|
); |
78
|
1 |
|
} |
79
|
1 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Print annotations by target with the printer. |
84
|
|
|
* @param string $targetName |
85
|
|
|
* @param \ArrayIterator $annotations |
86
|
|
|
* @return \Brickoo\Component\Annotation\AnnotationReaderResultPrinter |
87
|
|
|
*/ |
88
|
1 |
|
private function printAnnotationsByTarget($targetName, \ArrayIterator $annotations) { |
89
|
1 |
|
foreach ($annotations as $annotation) { |
90
|
1 |
|
$this->getPrinter() |
91
|
1 |
|
->addText(sprintf("Annotation => @%s [%s] %s", |
92
|
1 |
|
$annotation->getName(), $targetName, $annotation->getTargetLocation())) |
93
|
1 |
|
->nextLine() |
94
|
1 |
|
->indent(2); |
95
|
1 |
|
foreach ($annotation->getValues() as $param => $value) { |
96
|
1 |
|
$this->getPrinter() |
97
|
1 |
|
->addText(sprintf("param => (%s) %s", gettype($param), $param)) |
98
|
1 |
|
->indent(2) |
99
|
1 |
|
->addText(sprintf("value => (%s) %s", gettype($value), str_replace("\n", "", var_export($value, true)))) |
100
|
1 |
|
->nextLine(); |
101
|
1 |
|
} |
102
|
|
|
|
103
|
1 |
|
$this->getPrinter()->outdent(2); |
104
|
1 |
|
} |
105
|
1 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|