Ejemplo n.º 1
0
 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
Ejemplo n.º 2
0
 /**
  * Process file content
  *
  * @param File $asset
  * @return string
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $compiler = new \scssc();
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         return $compiler->compile($content);
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         return $errorMessage;
     }
 }
 /**
  * Preparation of content for the destination file
  *
  * @param string $path
  * @param string $content
  * @param string $module
  * @param FallbackContext $context
  * @return string
  */
 private function processContent($path, $content, $module, FallbackContext $context)
 {
     foreach ($this->alternativeSource->getAlternativesExtensionsNames() as $name) {
         $asset = $this->assetBuilder->setArea($context->getAreaCode())->setTheme($context->getThemePath())->setLocale($context->getLocale())->setModule($module)->setPath(preg_replace('#\\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#', '.' . $name, $path))->build();
         $processedContent = $this->assetSource->getContent($asset);
         if (trim($processedContent) !== '') {
             return $processedContent;
         }
     }
     return $content;
 }