Returns an array of usage reference objects.

@param AssetInterface $asset
@return array<\Neos\Neos\Domain\Model\Dto\AssetUsageInNodeProperties>
@throws \Neos\ContentRepository\Exception\NodeConfigurationException
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];
    }
781807
public function expandAssetGroups(array $assetGroups): array
    {
        $expandedAssetGroups = [];
        foreach ($assetGroups as $assetGroup) {
            if ('@' == substr($assetGroup, 0, 1)) {
                $group = substr($assetGroup, 1);
                $applicationAssetGroups = $this->getAssetGroups();
                if (!isset($applicationAssetGroups[$group])) {
                    $message = "Could not expand asset group \"$group\".";
                    $similarGroups = $this->findSimilarNames($group, array_keys($applicationAssetGroups));
                    if ($similarGroups) {
                        $message .= "\nDid you mean:\n" . implode("\n", $similarGroups) . "\n";
                    }
                    throw new Exception\DomainException($message);
                }

                $expandedAssetGroups = array_merge(
                    $expandedAssetGroups,
                    $this->expandAssetGroups($applicationAssetGroups[$group])
                );
            } else {
                $expandedAssetGroups[] = $assetGroup;
            }
        }

        sort($expandedAssetGroups);
        return $expandedAssetGroups;
    }
667607
public function filterDump(AssetInterface $asset)
    {
        $commandline =$this->nodeBin
            ? array($this->nodeBin, $this->uglifycssBin)
            : array($this->uglifycssBin);

        if ($this->expandVars) {
            array_push($commandline, '--expand-vars');
        }

        if ($this->uglyComments) {
            array_push($commandline, '--ugly-comments');
        }

        if ($this->cuteComments) {
            array_push($commandline, '--cute-comments');
        }

        // input and output files
        $input = FilesystemUtils::createTemporaryFile('uglifycss');

        file_put_contents($input, $asset->getContent());
        array_push($commandline, $input);

        $proc = new Process(implode(' ', $commandline));
        $code = $proc->run();
        unlink($input);

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

        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }

        $asset->setContent($proc->getOutput());
    }
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);
    }
947952
public function getRelatedNodes(AssetInterface $asset)
    {
        $relationMap = [];
        $relationMap[TypeHandling::getTypeForValue($asset)] = [$this->persistenceManager->getIdentifierByObject($asset)];

        if ($asset instanceof Image) {
            foreach ($asset->getVariants() as $variant) {
                $type = TypeHandling::getTypeForValue($variant);
                if (!isset($relationMap[$type])) {
                    $relationMap[$type] = [];
                }
                $relationMap[$type][] = $this->persistenceManager->getIdentifierByObject($variant);
            }
        }

        return $this->nodeDataRepository->findNodesByPathPrefixAndRelatedEntities(SiteService::SITES_ROOT_PATH, $relationMap);
    }
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);
    }
6558
private function cacheAsset(AssetInterface $asset)
    {
    	return $this->configuration->getCacheEnabled()
    	? new AssetCache($asset, new FilesystemCache($this->configuration->getCachePath()))
    	: $asset;
    }
925616
public function getUsageCount(AssetInterface $asset)
    {
        $usageCount = 0;
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usageCount += $strategy->getUsageCount($asset);
        }

        return $usageCount;
    }
1218722
public static function normalizeAssetTransformToObject($assetTransform): array
    {
        $transformArray = $assetTransform->toArray();
        $validParams = ['width', 'height', 'format', 'mode', 'position', 'interlace', 'quality'];

        $r = [];

        foreach ($validParams as $param) {
            if (isset($transformArray[$param])) {
                $r[$param] = $transformArray[$param];
            }
        }

        return $r;
    }
161176
public function getAssetType(string $assetType) : AssetTypeInterface
    {
        if (!isset($this->assetTypes[$assetType])) {
            if (isset($this->assetTypesArray[$assetType])) {
                $this->assetTypes[$assetType] = ImmutableAssetType::fromArray($assetType, $this->assetTypesArray[$assetType]);
            } else {
                $this->assetTypes[$assetType] = ImmutableAssetType::fromArray($assetType, []);
            }
        }
        return $this->assetTypes[$assetType];
    }
1030655
public function findReferencedNodes(): TraversableNodes
    {
        $referencedNodes = [];
        foreach ($this->getNodeType()->getProperties() as $propertyName => $property) {
            $propertyType = $this->getNodeType()->getPropertyType($propertyName);
            if ($propertyType === 'reference' && $this->getProperty($propertyName) instanceof TraversableNodeInterface) {
                $referencedNodes[] = $this->getProperty($propertyName);
            } elseif ($propertyName === 'references' && !empty($this->getProperty($propertyName))) {
                foreach ($this->getProperty($propertyName) as $node) {
                    if ($node instanceof TraversableNodeInterface) {
                        $referencedNodes[] = $node;
                    }
                }
            }
        }

        return TraversableNodes::fromArray($referencedNodes);
    }
323440
public function filterLoad(AssetInterface $asset)
    {
        $max_nesting_level = ini_get('xdebug.max_nesting_level');

        $memory_limit = ini_get('memory_limit');

        if ($max_nesting_level && $max_nesting_level < 200) {
            ini_set('xdebug.max_nesting_level', 200);
        }

        if ($memory_limit && $memory_limit < 256) {
            ini_set('memory_limit', '256M');
        }

        $root = $asset->getSourceRoot();
        $path = $asset->getSourcePath();

        $dirs = array();

        $lc = new \Less_Parser(array(
            'compress' => true,
        ));

        if ($root && $path) {
            $dirs[] = dirname($root.'/'.$path);
        }

        foreach ($this->loadPaths as $loadPath) {
            $dirs[] = $loadPath;
        }

        $lc->SetImportDirs($dirs);

        $url = parse_url($this->getRequest()->getUriForPath(''));

        // Strip the document root from the path.
        if (strpos($root, app('path.public')) !== false) {
            $absolutePath = str_replace(app('path.public'), '', $root);
        } elseif (strpos($root, app('path.resources')) !== false) {
            $absolutePath = str_replace(app('path.resources'), '', $root);
        }

        if (isset($url['path'])) {
            $absolutePath = $url['path'] . $absolutePath;
        }

        $lc->parseFile($root.'/'.$path, $absolutePath);

        $asset->setContent($lc->getCss());
    }
164946
public function findUsageReferenceInOtherSite($siteId, $entities)
    {
        $usedOtherSite = array();
        $supportedEntities = array(BlockInterface::ENTITY_TYPE, ContentInterface::ENTITY_TYPE);
        /** @var UseTrackableInterface $entity */
        foreach ($entities as $entity) {
            $references = $entity->getUseReferences();
            $entityReferences = array(
                'entity' => $entity,
                'references' => array()
            );
            if (!empty($references)) {
                foreach ($references as $type => $reference) {
                    if (in_array($type, $supportedEntities)) {
                        $referenceIds = array_keys($reference);
                        $repo = $this->getRepositoryByType($type);
                        foreach ($referenceIds as $referenceId) {
                            $referenceEntity = $repo->findById($referenceId);
                            if (
                                $siteId !== $referenceEntity->getSiteId()
                            ) {
                                $entityReferences['references'][$type][$referenceEntity->getId()] = $referenceEntity;
                            }
                        }
                    }
                }
                $usedOtherSite[] = $entityReferences;
            }
        }

        return $usedOtherSite;
    }
1329141
protected function getConsoleUsage(ConsoleAdapterInterface $console, $scriptName, ModuleManagerInterface $moduleManager = null)
    {
        /*
         * Loop through all loaded modules and collect usage info
        */
        $usageInfo = array();

        if ($moduleManager !== null) {
            foreach ($moduleManager->getLoadedModules(false) as $name => $module) {
                // Strict-type on ConsoleUsageProviderInterface, or duck-type
                // on the method it defines
                if (!$module instanceof ConsoleUsageProviderInterface && !method_exists($module, 'getConsoleUsage')) {
                    continue; // this module does not provide usage info
                }

                $moduleName = (method_exists($module, 'getConsoleLabel'))? $module->getConsoleLabel() : $name;

                if ($moduleName) {
                    // We prepend the usage by the module name (printed in red), so that each module is
                    // clearly visible by the user
                    $moduleName = sprintf("%s\n%s\n%s\n",
                        str_repeat('-', $console->getWidth()),
                        $moduleName,
                        str_repeat('-', $console->getWidth())
                    );

                    $moduleName = $console->colorize($moduleName, ColorInterface::RED);
                }

                $usage = $module->getConsoleUsage($console);

                if (is_array($usage) && !empty($usage)) {
                    $usageInfo[$name] = $usage;
                } elseif (is_string($usage) && ($usage != '')) {
                    $usageInfo[$name] = array($usage);
                }

                if ($moduleName && isset($usageInfo[$name])) {
                    array_unshift($usageInfo[$name], $moduleName);
                }
            }
        }

        /*
         * Handle an application with no usage information
        */
        if (!count($usageInfo)) {
            return '';
        }

        /*
         * Transform arrays in usage info into columns, otherwise join everything together
        */
        $result    = '';
        $table     = false;
        $tableCols = 0;
        $tableType = 0;
        foreach ($usageInfo as $moduleName => $usage) {
            if (!is_string($usage) && !is_array($usage)) {
                throw new mvcexceptions\RuntimeException(sprintf('Cannot understand usage info for module "%s"', $moduleName));
            }

            if (is_string($usage)) {
                // It's a plain string - output as is
                $result .= $usage . "\n";
                continue;
            }

            // It's an array, analyze it
            foreach ($usage as $a => $b) {
                /*
                 * 'invocation method' => 'explanation'
                */
                if (is_string($a) && is_string($b)) {
                    if (($tableCols !== 2 || $tableType != 1) && $table !== false) {
                        // render last table
                        $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                        $table   = false;

                        // add extra newline for clarity
                        $result .= "\n";
                    }

                    // Colorize the command
                    $a = $console->colorize($scriptName . ' ' . $a, ColorInterface::GREEN);

                    $tableCols = 2;
                    $tableType = 1;
                    $table[]   = array($a, $b);
                    continue;
                }

                /*
                 * array('--param', '--explanation')
                */
                if (is_array($b)) {
                    if ((count($b) != $tableCols || $tableType != 2) && $table !== false) {
                        // render last table
                        $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                        $table   = false;

                        // add extra newline for clarity
                        $result .= "\n";
                    }

                    $tableCols = count($b);
                    $tableType = 2;
                    $table[]   = $b;
                    continue;
                }

                /*
                 * 'A single line of text'
                */
                if ($table !== false) {
                    // render last table
                    $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                    $table   = false;

                    // add extra newline for clarity
                    $result .= "\n";
                }

                $tableType = 0;
                $result   .= $b . "\n";
            }
        }

        // Finish last table
        if ($table !== false) {
            $result .= $this->renderTable($table, $tableCols, $console->getWidth());
        }

        return $result;
    }
1225509
protected function getApplicationConfiguration(ContainerInterface $container): array
    {
        /** @var CacheSettingsProviderInterface $settingsProvider */
        $settingsProvider = $container->get(CacheSettingsProviderInterface::class);
        $appConfig        = $settingsProvider->getApplicationConfiguration();

        return $appConfig;
    }
807871
public function getReferences(): array
    {
        if (empty($this->parent)) {
            throw new NodeException("Unable to aggregate reference values, parent is missing");
        }

        if (empty($this->parent->references[$this->outerKey])) {
            return [];
        }

        return array_keys($this->parent->references[$this->outerKey]);
    }
1275546
protected function extractMediasFromContent(ContentInterface $content)
    {
        $references = array();

        /** @var ContentAttributeInterface $attribute */
        foreach ($content->getAttributes() as $attribute) {
            $references = array_merge($references, $this->extractMediasFromElement($attribute->getValue()));
        }

        return $references;
    }