DirectoryFilter.php 1.75 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 DirectoryFilter extends AbstractListFilter
29
{
30 31 32
    /**
     * @var string
     */
33
    public const CONF_TYPE = 'directories';
34

35 36 37 38
    /**
     * {@inheritDoc}
     */
    protected function extract(ReflectionClass $class): string
39
    {
40 41 42 43
        $filename = $class->getFileName();
        if ($filename === false) {
            return '';
        }
44 45
        return dirname($class->getFileName());
    }
46

47 48 49 50 51 52
    /**
     * @param mixed $tested
     * @param mixed $reference
     * @return bool
     */
    protected function matches($tested, $reference): bool
53
    {
54
        return strpos($tested, $reference) === 0;
55 56
    }

57 58 59 60 61
    /**
     * @param string $path
     * @return string
     */
    protected function normalize($path): string
62
    {
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
63
        return rtrim(strtr($path, '/\\', DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
64 65
    }
}