NamespaceFilter.php 1.46 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * This file is part of "irstea/plantuml-bundle".
 *
 * Copyright (C) 2016-2019 IRSTEA
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License and the GNU
 * Lesser General Public License along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
19
20
21
22
23
24
25
 */

namespace Irstea\PlantUmlBundle\Model\Filter;

use ReflectionClass;

/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
26
 * Description of DirectoryFilter.
27
 */
28
class NamespaceFilter extends AbstractListFilter
29
{
30
    public const CONF_TYPE = 'namespaces';
31

32
    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
33
     * {@inheritdoc}
34
35
     */
    protected function extract(ReflectionClass $class): string
36
37
38
    {
        return $class->getNamespaceName();
    }
39

40
    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
41
     * {@inheritdoc}
42
43
     */
    protected function matches($tested, $reference): bool
44
    {
45
        return strpos($tested, $reference) === 0;
46
47
    }

48
    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
49
     * {@inheritdoc}
50
51
     */
    protected function normalize($namespace): string
52
    {
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
53
        return trim($namespace, '\\') . '\\';
54
55
    }
}