1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of phpDocumentor. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Mike van Riel <[email protected]> |
11
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://phpdoc.org |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace phpDocumentor\Descriptor\Filter; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Descriptor\ConstantDescriptor; |
19
|
|
|
use phpDocumentor\Descriptor\FunctionDescriptor; |
20
|
|
|
use phpDocumentor\Descriptor\InterfaceDescriptor; |
21
|
|
|
use phpDocumentor\Descriptor\MethodDescriptor; |
22
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
23
|
|
|
use phpDocumentor\Descriptor\PropertyDescriptor; |
24
|
|
|
use phpDocumentor\Descriptor\TraitDescriptor; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Filter used to manipulate a descriptor after being build. |
28
|
|
|
* |
29
|
|
|
* This class is used during the building of descriptors. It passes the descriptor to each individual sub-filter, which |
30
|
|
|
* may change data in the descriptor or even remove it from the building process by returning null. |
31
|
|
|
*/ |
32
|
|
|
class Filter |
33
|
|
|
{ |
34
|
|
|
/** @var int default priority for a filter in the series of filters. */ |
35
|
|
|
const DEFAULT_PRIORITY = 1000; |
36
|
|
|
|
37
|
|
|
/** @var ClassFactory */ |
38
|
|
|
protected $factory; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructs the filter and attaches the factory to it. |
42
|
|
|
*/ |
43
|
1 |
|
public function __construct(ClassFactory $factory) |
44
|
|
|
{ |
45
|
1 |
|
$this->factory = $factory; |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
public function attachDefaults(ProjectDescriptorBuilder $descriptorBuilder): void |
49
|
|
|
{ |
50
|
|
|
$stripOnVisibility = new StripOnVisibility($descriptorBuilder); |
51
|
|
|
$filtersOnAllDescriptors = [ |
52
|
|
|
new StripInternal($descriptorBuilder), |
53
|
|
|
new StripIgnore($descriptorBuilder), |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
foreach ($filtersOnAllDescriptors as $filter) { |
57
|
|
|
$this->attach(ConstantDescriptor::class, $filter); |
58
|
|
|
$this->attach(FunctionDescriptor::class, $filter); |
59
|
|
|
$this->attach(InterfaceDescriptor::class, $filter); |
60
|
|
|
$this->attach(TraitDescriptor::class, $filter); |
61
|
|
|
$this->attach(PropertyDescriptor::class, $filter); |
62
|
|
|
$this->attach(MethodDescriptor::class, $filter); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->attach(PropertyDescriptor::class, $stripOnVisibility); |
66
|
|
|
$this->attach(MethodDescriptor::class, $stripOnVisibility); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Attaches a filter to a specific FQCN. |
71
|
|
|
*/ |
72
|
1 |
|
public function attach(string $fqcn, FilterInterface $filter): void |
73
|
|
|
{ |
74
|
1 |
|
$this->factory->attachTo($fqcn, $filter); |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Filters the given Descriptor and returns the altered object. |
79
|
|
|
*/ |
80
|
1 |
|
public function filter(Filterable $descriptor): ?Filterable |
81
|
|
|
{ |
82
|
1 |
|
$chain = $this->factory->getChainFor(get_class($descriptor)); |
83
|
|
|
|
84
|
1 |
|
return $chain($descriptor); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|