Neos\Flow\Aop\Builder\ClassNameIndex::filterByPrefix PHP Метод

filterByPrefix() публичный Метод

Returns a new index object which contains all class names of this index starting with the given prefix
public filterByPrefix ( string $prefixFilter ) : ClassNameIndex
$prefixFilter string A prefix string to filter the class names of this index
Результат ClassNameIndex A new index object
    public function filterByPrefix($prefixFilter)
    {
        $pointcuts = array_keys($this->classNames);
        $result = new ClassNameIndex();
        $right = count($pointcuts) - 1;
        $left = 0;
        $found = false;
        $currentPosition = -1;
        while ($found === false) {
            if ($left > $right) {
                break;
            }
            $currentPosition = $left + floor(($right - $left) / 2);
            if (strpos($pointcuts[$currentPosition], $prefixFilter) === 0) {
                $found = true;
                break;
            } else {
                $comparisonResult = strcmp($prefixFilter, $pointcuts[$currentPosition]);
                if ($comparisonResult > 0) {
                    $left = $currentPosition + 1;
                } else {
                    $right = $currentPosition - 1;
                }
            }
        }
        if ($found === true) {
            $startIndex = $currentPosition;
            while ($startIndex >= 0 && strpos($pointcuts[$startIndex], $prefixFilter) === 0) {
                $startIndex--;
            }
            $startIndex++;
            $endIndex = $currentPosition;
            while ($endIndex < count($pointcuts) && strpos($pointcuts[$endIndex], $prefixFilter) === 0) {
                $endIndex++;
            }
            $result->setClassNames(array_slice($pointcuts, $startIndex, $endIndex - $startIndex));
        }
        return $result;
    }

Usage Example

 /**
  * @test
  */
 public function filterByPrefixWork()
 {
     $index1 = new Aop\Builder\ClassNameIndex();
     $index1->setClassNames(['\\Foo\\Bar', '\\Foo\\Baz', '\\Bar\\Baz', '\\Foo\\Blubb']);
     // We need to call sort manually!
     $index1->sort();
     $filteredIndex = $index1->filterByPrefix('\\Foo');
     $this->assertEquals(['\\Foo\\Bar', '\\Foo\\Baz', '\\Foo\\Blubb'], $filteredIndex->getClassNames());
 }
All Usage Examples Of Neos\Flow\Aop\Builder\ClassNameIndex::filterByPrefix