Filters an asset after it has been loaded.

@param AssetInterface $asset An asset
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());
        }
    }
1318230
protected function replaceAssetDependencies(&$assets)
    {
        foreach ($assets as $asset => $value) {
            if (empty($replaces = $value['replaces'])) {
                continue;
            }

            foreach ($replaces as $replace) {
                unset($assets[$replace]);
            }

            $this->resolveDependenciesForAsset($assets, $asset, $replaces);
        }
    }
518539
public function getUsageReferences(AssetInterface $asset)
    {
        $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
        if (isset($this->firstlevelCache[$assetIdentifier])) {
            return $this->firstlevelCache[$assetIdentifier];
        }

        $relatedNodes = array_map(function (NodeData $relatedNodeData) use ($asset) {
            return new AssetUsageInNodeProperties($asset,
                $relatedNodeData->getIdentifier(),
                $relatedNodeData->getWorkspace()->getName(),
                $relatedNodeData->getDimensionValues(),
                $relatedNodeData->getNodeType()->getName()
            );
        }, $this->getRelatedNodes($asset));

        $this->firstlevelCache[$assetIdentifier] = $relatedNodes;
        return $this->firstlevelCache[$assetIdentifier];
    }
1058517
protected function initializeView(ViewInterface $view): void
    {
        $view->assignMultiple([
            'view' => $this->browserState->get('view'),
            'sortBy' => $this->browserState->get('sortBy'),
            'sortDirection' => $this->browserState->get('sortDirection'),
            'filter' => $this->browserState->get('filter'),
            'activeTag' => $this->browserState->get('activeTag'),
            'activeAssetCollection' => $this->browserState->get('activeAssetCollection'),
            'assetSources' => $this->assetSources,
            'variantsTabFeatureEnabled' => $this->settings['features']['variantsTab']['enable']
        ]);
    }
1130014
private function applyWorkers(AssetCollectionInterface $asset)
    {
        foreach ($asset as $leaf) {
            foreach ($this->workers as $worker) {
                $retval = $worker->process($leaf, $this);

                if ($retval instanceof AssetInterface && $leaf !== $retval) {
                    $asset->replaceLeaf($leaf, $retval);
                }
            }
        }

        foreach ($this->workers as $worker) {
            $retval = $worker->process($asset, $this);

            if ($retval instanceof AssetInterface) {
                $asset = $retval;
            }
        }

        return $asset instanceof AssetCollectionInterface ? $asset : $this->createAssetCollection(array($asset));
    }
1007920
public function registerCreatedAsset(AssetInterface $asset)
    {
        if (!$asset instanceof AssetVariantInterface || !$asset instanceof AssetSourceAwareInterface) {
            return;
        }

        $variantAssetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
        $originalAsset = $asset->getOriginalAsset();
        $originalAssetIdentifier = $this->persistenceManager->getIdentifierByObject($originalAsset);

        $originalImportedAsset = $this->importedAssetRepository->findOneByLocalAssetIdentifier($originalAssetIdentifier);
        if ($originalImportedAsset instanceof ImportedAsset) {
            $asset->setAssetSourceIdentifier($originalImportedAsset->getAssetSourceIdentifier());

            $variantImportedAsset = new ImportedAsset(
                $originalImportedAsset->getAssetSourceIdentifier(),
                $originalImportedAsset->getRemoteAssetIdentifier(),
                $variantAssetIdentifier, new \DateTimeImmutable(),
                $originalAssetIdentifier
            );

            $this->importedAssetRepository->add($variantImportedAsset);
            $this->logger->debug(sprintf('Asset created: %s / %s', $asset->getResource()->getFilename(), $this->persistenceManager->getIdentifierByObject($asset)));
        }
    }
1093662
public function assets(AssetFactory $asset)
    {
        $asset->load('jquery', [
            'type' => 'script',
        ])->area('admin');

        $asset->load('wp-color-picker', [
            'type' => 'style',
        ])->area('admin');

        $asset->add('fielder-colorpicker-styles', [
            'path' => FIELDER_URI.'public/css/colorpicker.css',
        ])->area('admin');

        $asset->add('fielder-colorpicker', [
            'path' => FIELDER_URI.'public/js/colorpicker.js',
            'dependences' => ['fielder', 'wp-color-picker'],
        ])->area('admin');
    }
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;
    }
1266588
public function locateAsset($asset)
    {
        if (substr($asset, 0, strlen($this->prefix)) === $this->prefix) {
            $locatedAsset = $this->resolveAlias($asset);
        } else {
            $locatedAsset = $asset;
        }

        if (!file_exists($locatedAsset)) {
            throw new AssetNotFoundException(sprintf('Asset not found (%s, resolved to %s)', $asset, $locatedAsset));
        }

        return $locatedAsset;
    }
632079
public function addAsset(array $Asset) {
        if (isset($Asset['name']) && ! array_key_exists($Asset['name'], $this->holder)) {
            $this->holder[$Asset['name']] = $Asset;
        }
    }
921116
public function getUsageReferences(AssetInterface $asset)
    {
        $usages = [];
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usages = Arrays::arrayMergeRecursiveOverrule($usages, $strategy->getUsageReferences($asset));
        }

        return $usages;
    }
658013
protected function evaluateAsset($asset, $value, $original, &$sorted, &$assets)
    {
        if (count($assets[$asset]['dependencies']) == 0) {
            $sorted[$asset] = $value;

            unset($assets[$asset]);
        }
        else {
            $this->evaluateAssetWithDependencies($asset, $original, $sorted, $assets);
        }
    }
925616
public function getUsageCount(AssetInterface $asset)
    {
        $usageCount = 0;
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usageCount += $strategy->getUsageCount($asset);
        }

        return $usageCount;
    }
995904
public function purge (Asset $asset)
    {
        $url = $this->getImgixUrl($asset);

        Craft::trace(
            Craft::t(
                'imgix',
                'Purging asset #{id}: {url}', [ 'id' => $asset->id, 'url' => $url ]
            ),
            'imgix');

        return $this->purgeUrl($url);
    }
215730
public function assignUploadedAssetToSiteAssetCollection(Asset $asset, NodeInterface $node, string $propertyName)
    {
        $contentContext = $node->getContext();
        if (!$contentContext instanceof ContentContext) {
            return;
        }
        $site = $contentContext->getCurrentSite();
        if ($site === null) {
            return;
        }
        $assetCollection = $site->getAssetCollection();
        if ($assetCollection === null) {
            return;
        }
        $assetCollection->addAsset($asset);
        $this->assetCollectionRepository->update($assetCollection);
    }
224226
public function deleteAction(Asset $asset): void
    {
        $usageReferences = $this->assetService->getUsageReferences($asset);
        if (count($usageReferences) > 0) {
            $this->addFlashMessage('deleteRelatedNodes', '', Message::SEVERITY_WARNING, [], 1412422767);
            $this->redirect('index');
        }

        $this->assetRepository->remove($asset);
        $this->addFlashMessage('assetHasBeenDeleted', '', Message::SEVERITY_OK, [$asset->getLabel()], 1412375050);
        $this->redirect('index');
    }
755136
public function registerAsset($context, $asset)
    {
        return $this->resolveAndCall($asset, 'register', [
            isset($context['this']) ? $context['this'] : null,
        ]);
    }