Neos\Flow\ObjectManagement\CompileTimeObjectManager::applyClassFilterConfiguration PHP Method

applyClassFilterConfiguration() protected method

Filters the classnames available for object management by filter expressions that either include or exclude classes.
protected applyClassFilterConfiguration ( array $classNames, array $filterConfiguration, string $includeOrExclude = 'include' ) : array
$classNames array All classnames per package
$filterConfiguration array The filter configuration to apply
$includeOrExclude string if this is an "include" or "exclude" filter
return array the remaining class
    protected function applyClassFilterConfiguration($classNames, $filterConfiguration, $includeOrExclude = 'include')
    {
        if (!in_array($includeOrExclude, ['include', 'exclude'])) {
            throw new \InvalidArgumentException('The argument $includeOrExclude must be one of "include" or "exclude", the given value was not allowed.', 1423726253);
        }
        foreach ($filterConfiguration as $packageKey => $filterExpressions) {
            if (!array_key_exists($packageKey, $classNames)) {
                $this->systemLogger->log('The package "' . $packageKey . '" specified in the setting "Neos.Flow.object.' . $includeOrExclude . 'Classes" was either excluded or is not loaded.', LOG_DEBUG);
                continue;
            }
            if (!is_array($filterExpressions)) {
                throw new InvalidConfigurationTypeException('The value given for setting "Neos.Flow.object.' . $includeOrExclude . 'Classes.\'' . $packageKey . '\'" is  invalid. It should be an array of expressions. Check the syntax in the YAML file.', 1422357272);
            }
            $classesForPackageUnderInspection = $classNames[$packageKey];
            $classNames[$packageKey] = [];
            foreach ($filterExpressions as $filterExpression) {
                $classesForPackageUnderInspection = array_filter($classesForPackageUnderInspection, function ($className) use($filterExpression, $includeOrExclude) {
                    $match = preg_match('/' . $filterExpression . '/', $className);
                    return $includeOrExclude === 'include' ? $match === 1 : $match !== 1;
                });
                if ($includeOrExclude === 'include') {
                    $classNames[$packageKey] = array_merge($classNames[$packageKey], $classesForPackageUnderInspection);
                    $classesForPackageUnderInspection = $classNames[$packageKey];
                } else {
                    $classNames[$packageKey] = $classesForPackageUnderInspection;
                }
            }
            if ($classNames[$packageKey] === []) {
                unset($classNames[$packageKey]);
            }
        }
        return $classNames;
    }