Returns the repository for an asset

@param AssetInterface $asset
@return RepositoryInterface
@api
690
public function getRepository(AssetInterface $asset)
    {
        $assetRepositoryClassName = str_replace('\\Model\\', '\\Repository\\', get_class($asset)) . 'Repository';

        if (class_exists($assetRepositoryClassName)) {
            return $this->objectManager->get($assetRepositoryClassName);
        }

        return $this->objectManager->get(AssetRepository::class);
    }
247977
public function asset($asset, $version = null)
    {
        $host = $this->request->getHost();
        $port = $this->request->getPort();
        $path = $this->request->getBasePath();

        if ('/' !== substr($asset, 1)) {
            $asset = '/'.$asset;
        }

        if (80 === $port) {
            $port = '';
        } else {
            $port = ':'.$port;
        }

        return '//'.$host.$port.$path.$asset;
    }
194581
public function filterDump(AssetInterface $asset)
    {
        $commandline = $this->nodeBin
            ? array($this->nodeBin, $this->uglifyjsBin)
            : array($this->uglifyjsBin);

        if ($this->noCopyright) {
            array_push($commandline, '--no-copyright');
        }

        if ($this->beautify) {
            array_push($commandline, '--beautify');
        }

        if ($this->unsafe) {
            array_push($commandline, '--unsafe');
        }

        if (false === $this->mangle) {
            array_push($commandline, '--no-mangle');
        }

        if ($this->defines) {
            foreach ($this->defines as $define) {
                array_push($commandline, '-d', $define);
            }
        }

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

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

        $proc = new Process(implode(' ', $commandline));
        $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);
    }
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);
    }
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());
    }
1055968
public function url($asset)
    {   
        $url = $this->parsePathAlias($asset, false);

        return $this->buildUrl($url);
    }
224563
public function filterDump(AssetInterface $asset)
    {
        $pb = $this->createProcessBuilder($this->nodeBin
            ? array($this->nodeBin, $this->cleanCssBin)
            : array($this->cleanCssBin));

        if ($this->keepLineBreaks) {
            $pb->add('--keep-line-breaks');
        }

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

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

        if ($this->rootPath) {
            $pb->add('--root ' .$this->rootPath);
        }

        if ($this->skipImport) {
            $pb->add('--skip-import');
        }

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

        if ($this->roundingPrecision) {
            $pb->add('--rounding-precision ' .$this->roundingPrecision);
        }

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

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

        if ($this->semanticMerging) {
            $pb->add('--semantic-merging');
        }

        if ($this->skipAdvanced) {
            $pb->add('--skip-advanced');
        }

        if ($this->skipAggresiveMerging) {
            $pb->add('--skip-aggressive-merging');
        }

        if ($this->skipImportFrom) {
            $pb->add('--skip-import-from ' .$this->skipImportFrom);
        }

        if ($this->mediaMerging) {
            $pb->add('--skip-media-merging');
        }

        if ($this->skipRebase) {
            $pb->add('--skip-rebase');
        }

        if ($this->skipRestructuring) {
            $pb->add('--skip-restructuring');
        }

        if ($this->skipShorthandCompacting) {
            $pb->add('--skip-shorthand-compacting');
        }

        if ($this->sourceMap) {
            $pb->add('--source-map');
        }

        if ($this->sourceMapInlineSources) {
            $pb->add('--source-map-inline-sources');
        }
        // input and output files
        $input = tempnam(sys_get_temp_dir(), 'input');

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

        $proc = $pb->getProcess();
        $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());
    }
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);
    }
1107275
protected function getAssetPath(Asset $asset):string
    {
        // Get the file name from the provider data
        $data = $asset->getProviderData();
        $path = $this->getRootPath() . "/" . $this->getCategoryDirectory() . "/" . $data["file"];
        return $path;
    }
921116
public function getUsageReferences(AssetInterface $asset)
    {
        $usages = [];
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usages = Arrays::arrayMergeRecursiveOverrule($usages, $strategy->getUsageReferences($asset));
        }

        return $usages;
    }
585776
public function replaceAssetResource(AssetInterface $asset, PersistentResource $resource, array $options = [])
    {
        $originalAssetResource = $asset->getResource();
        $asset->setResource($resource);

        if (isset($options['keepOriginalFilename']) && (boolean)$options['keepOriginalFilename'] === true) {
            $asset->getResource()->setFilename($originalAssetResource->getFilename());
        }

        $uriMapping = [];
        $redirectHandlerEnabled = isset($options['generateRedirects']) && (boolean)$options['generateRedirects'] === true && $this->packageManager->isPackageAvailable('Neos.RedirectHandler');
        if ($redirectHandlerEnabled) {
            $originalAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalAssetResource));
            $newAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($asset->getResource()));
            $uriMapping[$originalAssetResourceUri->getPath()] = $newAssetResourceUri->getPath();
        }

        if (method_exists($asset, 'getVariants')) {
            $variants = $asset->getVariants();
            /** @var AssetVariantInterface $variant */
            foreach ($variants as $variant) {
                $originalVariantResource = $variant->getResource();
                $variant->refresh();

                if (method_exists($variant, 'getAdjustments')) {
                    foreach ($variant->getAdjustments() as $adjustment) {
                        if (method_exists($adjustment, 'refit') && $this->imageService->getImageSize($originalAssetResource) !== $this->imageService->getImageSize($resource)) {
                            $adjustment->refit($asset);
                        }
                    }
                }

                if ($redirectHandlerEnabled) {
                    $originalVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalVariantResource));
                    $newVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($variant->getResource()));
                    $uriMapping[$originalVariantResourceUri->getPath()] = $newVariantResourceUri->getPath();
                }

                $this->getRepository($variant)->update($variant);
            }
        }

        if ($redirectHandlerEnabled) {
            /** @var RedirectStorageInterface $redirectStorage */
            $redirectStorage = $this->objectManager->get(RedirectStorageInterface::class);
            foreach ($uriMapping as $originalUri => $newUri) {
                $existingRedirect = $redirectStorage->getOneBySourceUriPathAndHost($originalUri);
                if ($existingRedirect === null) {
                    $redirectStorage->addRedirect($originalUri, $newUri, 301);
                }
            }
        }

        $this->getRepository($asset)->update($asset);
        $this->emitAssetResourceReplaced($asset);
    }
273261
public function getAssetStorageAccount($asset)
    {
        $assetId = Utilities::getEntityId(
            $asset,
            'WindowsAzure\MediaServices\Models\Asset'
        );

        return StorageAccount::createFromOptions(
            $this->_getEntity("Assets('{$assetId}')/StorageAccount")
        );
    }
752160
public function read(AssetInterface $asset_holder)
    {
        /*
         * add the included directories and files
         */
        $this->includeThis($asset_holder);
        /*
         * exclude the ignored directories and files
         */
        $this->excludeThis($asset_holder);

        // user terminal message
        $this->console->writeln('<fg=yellow>Files to upload:</fg=yellow>');

        // get all allowed 'for upload' files objects (assets) and store them in an array
        $assets = [];
        foreach ($this->files() as $file) {
            // user terminal message
            $this->console->writeln('<fg=cyan>'.'Path: '.$file->getRealpath().'</fg=cyan>');

            $assets[] = $file;
        }

        return new Collection($assets);
    }
204524
protected function getAssetPath(string $asset): string
    {
        $assetConfig = $this->applicationConfig->getSnapshotConfig()->getAssets();
        $location = $assetConfig[$asset]['location'] ?? 'code';
        $path = $this->applicationConfig->getPath($location);
        return "$path/$asset";
    }
1229189
private function getRepository($entity)
    {
        if (!array_key_exists($entity, $this->repositories)) {
            throw new \InvalidArgumentException("'$entity' is not a valid repository. One of [".implode(', ', array_keys($this->repositories)).'] is expected.');
        }

        return $this->repositories[$entity];
    }
231819
public function assetsWithMetadataAction(array $assets)
    {
        $this->response->setHeader('Content-Type', 'application/json');

        $result = [];
        foreach ($assets as $asset) {
            $result[] = $this->getAssetProperties($asset);
        }
        return json_encode($result);
    }
423768
public function setCache($path, AssetInterface $asset)
    {
        $provider = $this->getProvider($path);

        if (!$provider instanceof CacheInterface) {
            return $asset;
        }

        $assetCache             = new AssetCache($asset, $provider);
        $assetCache->mimetype   = $asset->mimetype;

        return $assetCache;
    }