Display assets through renderer

@param  array $aAssetFiles
@return \AssetsBundle\Service\Service
@throws \InvalidArgumentException
@throws \DomainException
340466
protected function displayAssets(array $aAssetFiles)
    {
        // Retrieve options
        $oOptions = $this->getOptions();

        // Arbitrary last modified time in production
        $iLastModifiedTime = $oOptions->isProduction() ? $oOptions->getLastModifiedTime() : null;

        // Use to cache loaded plugins
        $aRendererPlugins = array();

        // Render asset files
        foreach ($aAssetFiles as $oAssetFile) {
            if (!($oAssetFile instanceof \AssetsBundle\AssetFile\AssetFile)) {
                throw new \InvalidArgumentException(sprintf(
                    'Asset file expects an instance of "AssetsBundle\AssetFile\AssetFile", "%s" given',
                    is_object($oAssetFile) ? get_class($oAssetFile) : gettype($oAssetFile)
                ));
            }

            switch ($sAssetFileType = $oAssetFile->getAssetFileType()) {
                case \AssetsBundle\AssetFile\AssetFile::ASSET_JS:
                    $oRendererPlugin = isset($aRendererPlugins[$sAssetFileType]) ? $aRendererPlugins[$sAssetFileType] : $aRendererPlugins[$sAssetFileType] = $oOptions->getViewHelperPluginForAssetFileType($sAssetFileType);
                    $oRendererPlugin->appendFile($oOptions->getAssetFileBaseUrl($oAssetFile, $iLastModifiedTime));
                    break;
                case \AssetsBundle\AssetFile\AssetFile::ASSET_CSS:
                    $oRendererPlugin = isset($aRendererPlugins[$sAssetFileType]) ? $aRendererPlugins[$sAssetFileType] : $aRendererPlugins[$sAssetFileType] = $oOptions->getViewHelperPluginForAssetFileType($sAssetFileType);
                    $oRendererPlugin->appendStylesheet($oOptions->getAssetFileBaseUrl($oAssetFile, $iLastModifiedTime), 'all');
                    break;
                default:
                    throw new \DomainException('Asset\'s type "' . $oAssetFile->getAssetFileType() . '" can not be rendering as asset');
            }
        }
        return $this;
    }
69234
public static function process($assets)
    {
        if ($directory = self::getOutputDirectory()) {
            $relativeDirectory = self::getRelativeOutputDirectory();
            $filename = '';
            $sourceFiles = array();
            for ($i = 0; $i < count($assets); ++$i) {
                $asset = $assets[$i];
                $filename .= $asset->getAssetHashKey();
                $sourceFiles[] = $asset->getAssetURL();
            }
            $filename = sha1($filename);
            $cacheFile = $directory.'/'.$filename.'.js';
            if (!file_exists($cacheFile)) {
                $js = '';
                foreach ($assets as $asset) {
                    $contents = $asset->getAssetContents();
                    if (isset($contents)) {
                        if ($asset->assetSupportsMinification()) {
                            $contents = \JShrink\Minifier::minify($contents);
                        }
                        $js .= $contents.";\n\n";
                    }
                }
                @file_put_contents($cacheFile, $js);
            }

            $asset = new self();
            $asset->setAssetURL($relativeDirectory.'/'.$filename.'.js');
            $asset->setAssetPath($directory.'/'.$filename.'.js');
            $asset->setCombinedAssetSourceFiles($sourceFiles);

            return array($asset);
        }

        return $assets;
    }
438504
final protected function renderForm(array $arguments)
    {
        /*
         * We begin by setting up the form service: request results and form
         * instance are inserted in the service, and are used afterwards.
         *
         * There are only two ways to be sure the values injected are correct:
         * when the form was actually submitted by the user, or when the
         * argument `object` of the view helper is filled with a form instance.
         */
        $this->formService->activateFormContext();

        /*
         * If the form was submitted, applying custom behaviours on its fields.
         */
        $this->formService->applyBehavioursOnSubmittedForm($this->controllerContext);

        /*
         * Adding the default class configured in TypoScript configuration to
         * the form HTML tag.
         */
        $this->addDefaultClass();

        /*
         * Handling data attributes that are added to the form HTML tag,
         * depending on several parameters.
         */
        $this->handleDataAttributes();

        /*
         * Including JavaScript and CSS assets in the page renderer.
         */
        $this->handleAssets();

        $this->timeTracker->logTime('pre-render');

        /*
         * Getting the result of the original Fluid `FormViewHelper` rendering.
         */
        $result = $this->getParentRenderResult($arguments);

        /*
         * Language files need to be included at the end, because they depend on
         * what was used by previous assets.
         */
        $this->getAssetHandlerConnectorManager()
            ->getJavaScriptAssetHandlerConnector()
            ->includeLanguageJavaScriptFiles();

        return $result;
    }
1231171
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /* @var AssetsOptions $options */
        $options        = $serviceLocator->get('AcAssets\Options\AssetsOptions');
        $headScript     = $serviceLocator->get("viewhelpermanager")->get('headscript');
        $inlineScript   = $serviceLocator->get("viewhelpermanager")->get('inlinescript');
        $headLink       = $serviceLocator->get("viewhelpermanager")->get('headlink');

        return new AssetsService($headScript, $inlineScript, $headLink, $options);
    }
376803
public function build(array $filters = [])
    {
        $assets = [];
        foreach (array_keys($this->_queued) as $alias) {
            $this->_resolveDependencies($this->_collection->get($alias), $assets);
        }

        /** @var Asset $asset */
        $result = [
            Asset::TYPE_JS_FILE  => [],
            Asset::TYPE_JS_CODE  => [],
            Asset::TYPE_JSX_FILE => [],
            Asset::TYPE_JSX_CODE => [],
            Asset::TYPE_CSS_FILE => [],
            Asset::TYPE_CSS_CODE => [],
            Asset::TYPE_CALLBACK => [],
        ];
        foreach ($assets as $asset) {

            $source = $asset->load($filters);

            if (Asset::TYPE_COLLECTION === $source[0]) {
                $source = $source[1];
            } else {
                $source = [$source];
            }

            foreach ($source as $sourceItem) {

                $type = $sourceItem[0];
                $src = $sourceItem[1];

                if ($src && !Arr::in($src, $result[$type])) {
                    $result[$type][] = $src;
                }
            }
        }

        return $result;
    }
393988
public function prepareAssets($assets_directory, \Smarty_Internal_Template $smarty)
    {
        // Be sure to use the proper path separator
        if (DS != '/') {
            $assets_directory = str_replace('/', DS, $assets_directory);
        }

        // Set the current template assets directory
        self::$assetsDirectory = $assets_directory;

        /** @var SmartyParser $smartyParser */
        $smartyParser = $smarty->smarty;

        $this->prepareTemplateAssets($smartyParser->getTemplateDefinition(), $assets_directory, $smartyParser);
    }
431486
public function display($defaultFilters = null) {

		$this->extend();

		$this->fillBuffer();

		// check whether pre-configured filters are already in place
		
		if(is_null($defaultFilters)) {

			// add default filters

			$this->defaultFilters = [
				new AnchorHref(),
				new ImageCache(),
				// new AssetsPath()
			];

			if(!$this->ignoreLocales) {
                $this->defaultFilters[] = new LocalizedPhrases();
			}

		}

		else {

		    $this->defaultFilters = $defaultFilters;

            if(!$this->ignoreLocales) {

                // check whether adding a localization filter is necessary

                $found = false;

                foreach($this->defaultFilters as $filter) {

                    if($filter instanceof LocalizedPhrases) {
                        $found = true;
                        break;
                    }

                }

                if(!$found) {
                    $this->defaultFilters[] = new LocalizedPhrases();
                }
            }

        }

        // add configured filters

        if($templatingConfig = Application::getInstance()->getConfig()->templating) {

            foreach($templatingConfig->filters as $id => $filter) {

                if(!in_array($id, $this->blockedFilters)) {

                    // load class file

                    $instance = new $filter['class']();

                    // check whether instance implements FilterInterface

                    if (!$instance instanceof SimpleTemplateFilterInterface) {
                        throw new SimpleTemplateException(sprintf("Template filter '%s' (class %s) does not implement the SimpleTemplateFilterInterface.", $id, $filter['class']));
                    }

                    $this->defaultFilters[] = $instance;

                }
            }
        }

        $this->applyFilters();

		return $this->contents;
	}
307284
protected function assets_callback($matches)
    {
        $file = $this->asset_url($matches[3]);

        return $matches[1] . '=' . $matches[2] . $file . $matches[4];
    }
473813
public function asset($encPath, $contentType, Filesystem $fileSystem)
    {
        return $this->service->asset($encPath, $contentType, $fileSystem);
    }
753349
public function setCssFiles(array $cssFiles)
    {
        $this->cssFiles = ArrayUtils::merge($this->cssFiles, $cssFiles);
        return $this;
    }
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);
        }
    }
762989
protected function cacheCssAssetFiles()
    {

        // Cache media asset files
        $this->cacheMediaAssetFiles();

        if ($this->getOptions()->isProduction()) {
            // Retrieve asset file filters manager
            $oAssetFileFiltersManager = $this->getAssetFileFiltersManager();

            // Retrieve Css file filter if available
            $oCssFileFilter = $oAssetFileFiltersManager->has(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS) ? $oAssetFileFiltersManager->get(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS) : null;

            // Create tmp asset file
            $oTmpAssetFile = $this->createTmpAssetFile(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS);

            // Merge less asset files
            foreach ($this->cacheLessAssetFiles() as $oAssetFile) {
                $oTmpAssetFile->setAssetFileContents($this->rewriteAssetFileUrls(
                    // File content
                    $oCssFileFilter ? $oCssFileFilter->filterAssetFile($oAssetFile) : $oAssetFile->getAssetFileContents(),
                    // Current asset file
                    $oAssetFile
                ). PHP_EOL);

                // Remove temp less asset file
                \Zend\Stdlib\ErrorHandler::start();
                unlink($oAssetFile->getAssetFilePath());
                \Zend\Stdlib\ErrorHandler::stop(true);
            }

            // Merge css asset files
            foreach ($this->getAssetFilesConfiguration()->getAssetFiles(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS) as $oAssetFile) {
                $oTmpAssetFile->setAssetFileContents($this->rewriteAssetFileUrls(
                    // File content
                    $oCssFileFilter ? $oCssFileFilter->filterAssetFile($oAssetFile) : $oAssetFile->getAssetFileContents(),
                    // Current asset file
                    $oAssetFile
                ) . PHP_EOL);
            }

             // Cache asset file if not empty
            if($oTmpAssetFile->getAssetFileSize()){
                return array($this->getAssetFilesCacheManager()->cacheAssetFile($oTmpAssetFile));
            }
            return array();
        }

        // Cache less asset files
        $aAssetFiles = $this->cacheLessAssetFiles();

        // Retrieve asset files cache manager
        $oAssetFilesCacheManager = $this->getAssetFilesCacheManager();
        foreach ($this->getAssetFilesConfiguration()->getAssetFiles(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS) as $oAssetFile) {
            // Cache asset file if not empty
            if($oAssetFile->getAssetFileSize()){
                $aAssetFiles[] = $oAssetFilesCacheManager->cacheAssetFile($oAssetFile);
            }
        }
        return $aAssetFiles;
    }
307820
public function assetFiles(array $assets, array $options = []): string
    {
        $assets = $this->prepareAssets($assets);
        $options = array_replace_recursive($this->options, $options);

        $cacheKey = $this->getCacheKey($assets, $options);
        $cacheItem = $this->cache->getItem($cacheKey);
        if ($cacheItem->isHit()) {
            return $cacheItem->get();
        }

        $jsFiles = [];
        $cssFiles = [];
        foreach ($assets as $file) {
            $fileType = strtolower(pathinfo($file, PATHINFO_EXTENSION));
            if ($fileType === 'js') {
                $jsFiles[] = $file;
            }
            if ($fileType === 'css') {
                $cssFiles[] = $file;
            }
        }
        $cssContent = $this->css($cssFiles, $options);
        $jsContent = $this->js($jsFiles, $options);
        $result = $cssContent . $jsContent;

        $cacheItem->set($result);
        $this->cache->save($cacheItem);

        return $result;
    }
775924
public function renderScriptAssets()
    {
        return implode(
            "\n",
            array_map(
                function ($asset) {
                    return '<script src="' . $asset . '"></script>';
                },
                array_keys(
                    array_filter($this->scriptAssets, function ($head) { return ! $head; })
                )
            )
        );
    }
395174
public function call(ArrayAccess $services)
    {
        $callbackReflection = new CallableReflection($this->getController());
        return $callbackReflection->invokeA($this->prepareArgs($services, $callbackReflection));
    }
1012720
public function assets( $args, $assoc_args ) {
		list( $type ) = $args;
		$global = self::get_flag( 'global', $assoc_args );
		if ( false === array_search( $type, [ 'css', 'js' ] ) ) {
			self::e( $this->__( 'Only css and js are supported.' ) );
		}
		$header = [
			'Handle',
			'Source',
			'Dependency',
			'Version',
			'css' === $type ? 'Media' : 'Footer',
		];
		$rows   = [];
		if ( $global ) {
			switch ( $type ) {
				case 'js':

					break;
				case 'css':

					break;
				default:
					// Do nothing
					break;
			}
		} else {
			$assets = Library::all_assets()[ $type ];
			foreach ( $assets as $handle => $asset ) {
				$rows[] = array_merge( [ $handle ], array_map( function ( $var ) {
					if ( is_bool( $var ) ) {
						return $var ? 'Yes' : 'No';
					} elseif ( is_array( $var ) ) {
						return empty( $var ) ? '-' : implode( ', ', $var );
					} elseif ( is_null( $var ) ) {
						return '-';
					} else {
						return $var;
					}
				}, $asset ) );
			}
		}

		self::table( $header, $rows );
		self::l( '' );
		self::s( sprintf( '%d %s are available on WPametu.', count( $rows ), $type ) );
	}
449564
protected function getAssetFilesPathFromDirectory($sDirPath, $sAssetType)
    {
        if (!is_string($sDirPath) || !($sDirPath = $this->getOptions()->getRealPath($sDirPath)) && !is_dir($sDirPath)) {
            throw new \InvalidArgumentException('Directory not found : ' . $sDirPath);
        }
        if (!\AssetsBundle\AssetFile\AssetFile::assetFileTypeExists($sAssetType)) {
            throw new \InvalidArgumentException('Asset\'s type is undefined : ' . $sAssetType);
        }

        $oDirIterator = new \DirectoryIterator($sDirPath);
        $aAssets = array();
        $bRecursiveSearch = $this->getOptions()->allowsRecursiveSearch();

        // Defined expected extensions forthe given type
        if ($sAssetType === \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA) {
            $aExpectedExtensions = $this->getOptions()->getMediaExt();
        } else {
            $aExpectedExtensions = array(\AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension($sAssetType));
        }

        foreach ($oDirIterator as $oFile) {
            if ($oFile->isFile()) {
                if (in_array(strtolower(pathinfo($oFile->getFilename(), PATHINFO_EXTENSION)), $aExpectedExtensions, true)) {
                    $aAssets[] = $oFile->getPathname();
                }
            } elseif ($oFile->isDir() && !$oFile->isDot() && $bRecursiveSearch) {
                $aAssets = array_merge(
                        $aAssets, $this->getAssetFilesPathFromDirectory($oFile->getPathname(), $sAssetType)
                );
            }
        }
        return $aAssets;
    }