/** * Set up an asset. * * @param FileAssetInterface $asset * @param string $fileName * @param array $options */ private function setupAsset(FileAssetInterface $asset, $fileName, array $options) { $fileName = $this->getAssetPath($fileName); $options = array_merge(['late' => false, 'priority' => 0, 'attrib' => null], $this->getCompatibleArgs($options)); $asset->setFileName($fileName)->setLate($options['late'])->setPriority($options['priority'])->setAttributes($options['attrib']); return $asset; }
/** * Process a single asset. * * @param FileAssetInterface $asset * @param Request $request * @param Response $response */ protected function processAsset(FileAssetInterface $asset, Request $request, Response $response) { if ($asset->getZone() !== Zone::get($request)) { return; } elseif ($asset->isLate()) { $this->injector->inject($asset, Target::END_OF_BODY, $response); } elseif ($asset->getType() === 'stylesheet') { $this->injector->inject($asset, Target::BEFORE_CSS, $response); } elseif ($asset->getType() === 'javascript') { $this->injector->inject($asset, Target::AFTER_JS, $response); } }
/** * Normalizes the path and package name of the asset file. * * @param FileAssetInterface $asset */ private function normalizeAsset(FileAssetInterface $asset) { $path = $asset->getPath(); if ($path === null) { throw new \RuntimeException('Extension file assets must have a path set.'); } if ($this->isAbsoluteUrl($path)) { // Set asset to a package, since there is no default. // It doesn't matter which since it is absolute. $asset->setPackageName('extensions'); return; } $file = $this->getWebDirectory()->getFile($asset->getPath()); if ($file->exists()) { $asset->setPackageName('extensions')->setPath($file->getPath()); return; } $app = $this->getContainer(); $themeFile = $app['filesystem']->getFile(sprintf('theme://%s', $path)); if ($themeFile->exists()) { $asset->setPackageName('theme')->setPath($path); return; } $message = sprintf("Couldn't add file asset '%s': File does not exist in either %s or %s directories.", $path, $this->getWebDirectory()->getFullPath(), $themeFile->getFullPath()); $app['logger.system']->error($message, ['event' => 'extensions']); }
/** * Process a single asset. * * @param FileAssetInterface $asset * @param Request $request * @param Response $response */ protected function processAsset(FileAssetInterface $asset, Request $request, Response $response) { if ($asset->getZone() !== Zone::get($request)) { return; } elseif ($asset->isLate()) { if ($asset->getLocation() === null) { $location = Target::END_OF_BODY; } else { $location = $asset->getLocation(); } } elseif ($asset->getLocation() !== null) { $location = $asset->getLocation(); } else { $location = Target::END_OF_HEAD; } $this->injector->inject($asset, $location, $response); }
/** * Process the JavaScript asset queue. * * @param FileAssetInterface $asset * @param string $html * * @return string */ protected function processJsAssets(FileAssetInterface $asset, $html) { if ($asset->isLate()) { return $this->injector->inject($asset, Target::END_OF_BODY, $html); } else { return $this->injector->inject($asset, Target::AFTER_JS, $html); } }
/** * Normalizes the path and package name of the asset file. * * @param FileAssetInterface $asset */ private function normalizeAsset(FileAssetInterface $asset) { $path = $asset->getPath(); if ($path === null) { throw new \RuntimeException('Extension file assets must have a path set.'); } $file = $this->getWebDirectory()->getFile($asset->getPath()); if ($file->exists()) { $asset->setPackageName('extensions')->setPath($file->getPath()); return; } $app = $this->getContainer(); if ($app['filesystem']->has(sprintf('theme://%s', $path))) { $asset->setPackageName('theme')->setPath($path); return; } $message = sprintf("Couldn't add file asset '%s': File does not exist in either %s or %s directories.", $path, $this->getWebDirectory()->getFullPath(), $app['resources']->getUrl('theme')); $app['logger.system']->error($message, ['event' => 'extensions']); }