Sha256: dc979b1c909ba4333727e6f481961fff1498bf8193e792d6de12060830c065ef

Contents?: true

Size: 1.41 KB

Versions: 42

Compression:

Stored size: 1.41 KB

Contents

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * FilecontentFilterIterator filters files by their contents using patterns (regexps or strings).
 *
 * @author Fabien Potencier  <fabien@symfony.com>
 * @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
 */
class FilecontentFilterIterator extends MultiplePcreFilterIterator
{
    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        if (!$this->matchRegexps && !$this->noMatchRegexps) {
            return true;
        }

        $fileinfo = $this->current();

        if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
            return false;
        }

        $content = $fileinfo->getContents();
        if (!$content) {
            return false;
        }

        return $this->isAccepted($content);
    }

    /**
     * Converts string to regexp if necessary.
     *
     * @param string $str Pattern: string or regexp
     *
     * @return string regexp corresponding to a given string or regexp
     */
    protected function toRegex($str)
    {
        return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
    }
}

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
dependabot-composer-0.119.0.beta1 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.113.19 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.112.1 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.57 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.56 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.52 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.50 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.25 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.17 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.111.15 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.110.13 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.108.11 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.108.8 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.107.47 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.107.39 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.107.36 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.107.28 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.107.14 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.106.12 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
dependabot-composer-0.106.11 helpers/vendor/symfony/finder/Iterator/FilecontentFilterIterator.php