See if there are filters for the asset, and if so, set them.

@param   string          $path
@param   AssetInterface  $asset

@throws Exception\RuntimeException on invalid filters
320133
public function setFilters($path, AssetInterface $asset)
    {
        $config = $this->getConfig();

        if (!empty($config[$path])) {
            $filters = $config[$path];
        } elseif (!empty($config[$asset->mimetype])) {
            $filters = $config[$asset->mimetype];
        } else {
            $extension = $this->getMimeResolver()->getExtension($asset->mimetype);
            if (!empty($config[$extension])) {
                $filters = $config[$extension];
            } else {
                return;
            }
        }

        foreach ($filters as $filter) {
            if (is_null($filter)) {
                continue;
            }
            if (!empty($filter['filter'])) {
                $this->ensureByFilter($asset, $filter['filter']);
            } elseif (!empty($filter['service'])) {
                $this->ensureByService($asset, $filter['service']);
            } else {
                throw new Exception\RuntimeException(
                    'Invalid filter supplied. Expected Filter or Service.'
                );
            }
        }
    }
522019
public function editAction(string $assetSourceIdentifier, string $assetProxyIdentifier): void
    {
        if (!isset($this->assetSources[$assetSourceIdentifier])) {
            throw new \RuntimeException('Given asset source is not configured.', 1509632166);
        }

        $assetSource = $this->assetSources[$assetSourceIdentifier];
        $assetProxyRepository = $assetSource->getAssetProxyRepository();

        try {
            $assetProxy = $assetProxyRepository->getAssetProxy($assetProxyIdentifier);

            $tags = [];
            $contentPreview = 'ContentDefault';
            if ($assetProxyRepository instanceof SupportsTaggingInterface && $assetProxyRepository instanceof SupportsCollectionsInterface) {
                // TODO: For generic implementation (allowing other asset sources to provide asset collections), the following needs to be refactored:

                if ($assetProxy instanceof NeosAssetProxy) {
                    /** @var Asset $asset */
                    $asset = $assetProxy->getAsset();
                    $assetCollections = $asset->getAssetCollections();
                    $tags = $assetCollections->count() > 0 ? $this->tagRepository->findByAssetCollections($assetCollections->toArray()) : $this->tagRepository->findAll();

                    switch ($asset->getFileExtension()) {
                        case 'pdf':
                            $contentPreview = 'ContentPdf';
                            break;
                    }
                }
            }

            $this->view->assignMultiple([
                'tags' => $tags,
                'assetProxy' => $assetProxy,
                'assetCollections' => $this->assetCollectionRepository->findAll(),
                'contentPreview' => $contentPreview,
                'assetSource' => $assetSource,
                'canShowVariants' => ($assetProxy instanceof NeosAssetProxy) && ($assetProxy->getAsset() instanceof VariantSupportInterface)
            ]);
        } catch (AssetNotFoundExceptionInterface $e) {
            $this->throwStatus(404, 'Asset not found');
        } catch (AssetSourceConnectionExceptionInterface $e) {
            $this->view->assign('connectionError', $e);
        }
    }
514494
public function filterDump(AssetInterface $asset)
    {
        $pb = $this->createProcessBuilder($this->nodeBin
            ? array($this->nodeBin, $this->uglifyjsBin)
            : array($this->uglifyjsBin));

        if ($this->noCopyright) {
            $pb->add('--no-copyright');
        }

        if ($this->beautify) {
            $pb->add('--beautify');
        }

        if ($this->unsafe) {
            $pb->add('--unsafe');
        }

        if (false === $this->mangle) {
            $pb->add('--no-mangle');
        }

        // input and output files
        $input = tempnam(sys_get_temp_dir(), 'input');
        $output = tempnam(sys_get_temp_dir(), 'output');

        file_put_contents($input, $asset->getContent());
        $pb->add('-o')->add($output)->add($input);

        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);

        if (0 !== $code) {
            if (file_exists($output)) {
                unlink($output);
            }

            if (127 === $code) {
                throw new \RuntimeException('Path to node executable could not be resolved.');
            }

            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }

        if (!file_exists($output)) {
            throw new \RuntimeException('Error creating output file.');
        }

        $uglifiedJs = file_get_contents($output);
        unlink($output);

        $asset->setContent($uglifiedJs);
    }
466178
private function deployAsset($deploy, Asset $asset)
    {
        if ($this->loadDeployer($deploy)) {
            try {
                $this->deployersInstances[$deploy]->deploy($asset);
            } catch (PhassetsInternalException $e) {
                $this->loadedLogger->error('An error occurred while deploying the asset: ' . $e);
            }
        }
    }
533863
public function filterLoad(AssetInterface $asset)
    {
        $assetRoot      = $asset->getSourceRoot();
        $assetPath      = $asset->getSourcePath();
        $assetImportDir = dirname($assetRoot . '/' . $assetPath);
        $importDir      = $this->config->getBootstrapPath() . '/less';

        $this->setupLoadPaths($assetImportDir);

        // Make sure we _always_ have the bootstrap import dir.
        if ($importDir !== $assetImportDir) {
            $this->lessFilter->addLoadPath($importDir);
        }

        $variables = array_merge(
            $this->extractVariables($importDir . '/variables.less'),
            $this->config->getVariables()
        );

        $variablesString = '';

        foreach ($variables as $key => $value) {
            $variablesString .= "@$key:$value;" . PHP_EOL;
        }

        if ('bootstrap.less' === $assetPath) {

            $imports = $this->filterImportFiles(array_unique(array_merge(
                $this->extractImports($importDir . '/bootstrap.less'),
                $this->extractImports($importDir . '/responsive.less'),
                $this->config->getCustomComponents()
            )));

            $assetContent = $variablesString . $imports;

            $asset->setContent($assetContent);
        } else {
            $asset->setContent($variablesString . $asset->getContent());
        }

        $this->lessFilter->filterLoad($asset);
    }
685243
protected function filterProvidedAssets($asset)
    {
        foreach ($this->providedAssetGroup->getAssetPointers() as $pass) {
            if ($pass->getHandle() == $asset->getHandle() && $pass->getType() == $asset->getType()) {
                return false;
            }
        }

        // now is the unmatched assets something that matches this asset?
        // (ie, is it a path-style match, like bootstrap/* )
        foreach ($this->providedAssetGroupUnmatched as $assetPointer) {
            if ($assetPointer->getType() == $asset->getType() && fnmatch($assetPointer->getHandle(), $asset->getHandle())) {
                return false;
            }
        }

        return true;
    }
76892
public function setPropertyFilter(PropertyFilterInterface $filter)
    {
        $this->propertyFilter = $filter;

        $this->getReader()->setPropertyFilter($filter);
        $this->getWriter()->setPropertyFilter($filter);

        $dataVersionHash = $this->getDataVersionHash();
        $this->getReader()->setDataVersionHash($dataVersionHash);
        $this->getWriter()->setDataVersionHash($dataVersionHash);
    }
944175
public function setRuntimePath($path)
    {
        $this->_runtimePath = $this->getAlias($path);
        $this->setAlias('@runtime', $this->_runtimePath);
    }
346834
public function filterLoad(AssetInterface $asset)
    {
        if ('' != ($sourceRoot = $asset->getSourceRoot()) && '' != ($sourcePath = $asset->getSourcePath())) {
            $input = $sourceRoot . '/' . $sourcePath;
            $remove = false;
        } else {
            $input = tempnam(sys_get_temp_dir(), 'assetic_jshint');
            file_put_contents($input, $asset->getContent());
            $remove = true;
        }

        $pb = $this->createProcessBuilder(array($this->jsHintBinary));
        $pb->add($input);
        $proc = $pb->getProcess();
        $code = $proc->run();

        if (true === $remove) {
            unlink($input);
        }

        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
    }
1089686
protected function doLoad($content, FilterInterface $additionalFilter = null)
    {
        $filter = clone $this->filters;
        if ($additionalFilter) {
            $filter->ensure($additionalFilter);
        }

        $asset = clone $this;
        $asset->setContent($content);

        $filter->filterLoad($asset);
        $this->content = $asset->getContent();

        $this->loaded = true;
    }
1080859
public function collection(AssetTarget $target)
    {
        $filters = [];
        foreach ($target->filterNames() as $name) {
            $filter = $this->get($name);
            if ($filter === null) {
                throw new RuntimeException("Filter '$name' was not loaded/configured.");
            }
            // Clone filters so the registry is not polluted.
            $copy = clone $filter;
            $copy->settings([
                'target' => $target->name(),
                'paths' => $target->paths()
            ]);
            $filters[] = $copy;
        }
        return new FilterCollection($filters);
    }
430092
protected function processPath($path, $force)
    {
        $existsPath = $this->fs->exists($path);
        $isEmpty = $this->isEmptyDir($path);

        if ($existsPath === true && $force === false && $isEmpty === false) {
            throw new \RuntimeException(sprintf('Path "%s" exists and is not empty.', $path));
        }

        $existsPath ? $this->clearDir($path) : $this->fs->mkdir($path);
    }
915832
public function createAction(Asset $asset): void
    {
        if ($this->persistenceManager->isNewObject($asset)) {
            $this->assetRepository->add($asset);
        }
        $this->addFlashMessage('assetHasBeenAdded', '', Message::SEVERITY_OK, [htmlspecialchars($asset->getLabel())]);
        $this->redirect('index');
    }
925616
public function getUsageCount(AssetInterface $asset)
    {
        $usageCount = 0;
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usageCount += $strategy->getUsageCount($asset);
        }

        return $usageCount;
    }
464260
protected function applyFilters(&$propertyData, array $filterClasses)
    {
        /** @var FilterInterface $filter */
        foreach ($filterClasses as $filterClass => $filterClassArguments) {
            $filter = new $filterClass(...$filterClassArguments);

            if (!($filter instanceof FilterInterface)) {
                throw new \RuntimeException(sprintf('Filter %s must implement %s interface',
                    $filterClass, FilterInterface::class));
            }

            $propertyData = $filter->apply($propertyData);
        }
        
        return $propertyData;
    }
515133
private function excludeThis(AssetInterface $asset_holder)
    {
        // add or ignore hidden directories
        $this->ignoreDotFiles($asset_holder->getExcludeHidden());

        // exclude ignored files
        foreach ($asset_holder->getExcludedFiles() as $name) {
            $this->notName($name);
        }

        // exclude files (if exist) with this extensions
        $excluded_extensions = $asset_holder->getExcludedExtensions();
        if (!empty($excluded_extensions)) {
            foreach ($asset_holder->getExcludedExtensions() as $extension) {
                $this->notName('*'.$extension);
            }
        }

        // exclude the regex pattern
        foreach ($asset_holder->getExcludedPatterns() as $pattern) {
            $this->notName($pattern);
        }
    }
286655
protected function setFilter($filter, AssetInterface $asset)
    {
        if (is_null($filter)) {
            return;
        }

        if (!empty($filter['filter'])) {
            $this->ensureByFilter($asset, $filter['filter']);

            return;
        }

        if (!empty($filter['service'])) {
            $this->ensureByService($asset, $filter['service']);

            return;
        }

        throw new Exception\RuntimeException(
            'Invalid filter supplied. Expected Filter or Service.'
        );
    }