Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     // has path?
     if (!($path = $asset->getOption('path'))) {
         return;
     }
     // set base path
     $this->path = dirname($this->url->to($path)) . '/';
     $asset->setContent(preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', array($this, 'rewrite'), $asset->getContent()));
 }
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     // has path?
     if (!$asset['path']) {
         return;
     }
     // resolve @import rules
     $content = $this->load($asset['path'], $asset->getContent());
     // move unresolved @import rules to the top
     $comments = array();
     $regexp = '/@import[^;]+;/i';
     $content = $this->replaceComments($content, $comments);
     if (preg_match_all($regexp, $content, $matches)) {
         $content = preg_replace($regexp, '', $content);
         $content = implode("\n", $matches[0]) . "\n" . $content;
     }
     $content = $this->restoreComments($content, $comments);
     $asset->setContent($content);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     $images = array();
     $content = $asset->getContent();
     // get images and the related path
     if (preg_match_all('/url\\(\\s*[\'"]?([^\'"]+)[\'"]?\\s*\\)/Ui', $asset->getContent(), $matches)) {
         foreach ($matches[0] as $i => $url) {
             if (strpos($path = $matches[1][$i], $this->baseUrl) !== 0) {
                 continue;
             }
             if ($path = realpath($this->basePath . '/' . ltrim(substr($path, strlen($this->baseUrl)), '/'))) {
                 $images[$url] = $path;
             }
         }
     }
     // check if image exists and filesize < 10kb
     foreach ($images as $url => $path) {
         if (filesize($path) <= 10240 && preg_match('/\\.(gif|png|jpg)$/i', $path, $extension)) {
             $content = str_replace($url, sprintf('url(data:image/%s;base64,%s)', str_replace('jpg', 'jpeg', strtolower($extension[1])), base64_encode(file_get_contents($path))), $content);
         }
     }
     $asset->setContent($content);
 }
Exemplo n.º 4
0
 /**
  * Resolves asset dependencies.
  *
  * @param  AssetInterface   $asset
  * @param  AssetInterface[] $resolved
  * @param  AssetInterface[] $unresolved
  * @return AssetInterface[]
  * @throws \RuntimeException
  */
 public function resolveDependencies($asset, &$resolved = array(), &$unresolved = array())
 {
     $unresolved[$asset->getName()] = $asset;
     foreach ($asset->getDependencies() as $dependency) {
         if (!isset($resolved[$dependency])) {
             if (isset($unresolved[$dependency])) {
                 throw new \RuntimeException(sprintf('Circular asset dependency "%s > %s" detected.', $asset->getName(), $dependency));
             }
             if ($d = $this->registered->get($dependency)) {
                 $this->resolveDependencies($d, $resolved, $unresolved);
             }
         }
     }
     $resolved[$asset->getName()] = $asset;
     unset($unresolved[$asset->getName()]);
     return $resolved;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     $asset->setContent($this->process($asset->getContent()));
 }