Пример #1
0
 /**
  * Adds a converter.
  *
  * @param \Yosymfony\Spress\Core\ContentManager\Converter\ConverterInterface $converter The converter.
  *
  * @throws RuntimeException If invalid priority at the converter.
  */
 public function addConverter(ConverterInterface $converter)
 {
     $priority = $converter->getPriority();
     if (false === (is_int($priority) && $priority >= 0 && $priority <= 10)) {
         throw new \InvalidArgumentException(sprintf('Invalid priority at the converter: "%s".', get_class($converter)));
     }
     $this->queue->insert($converter, $priority);
 }
Пример #2
0
 /**
  * Generates a cache key based on provided data
  *
  * @param mixed $data
  *
  * @return string
  * @throws InvalidArgumentException in case if value was not converted
  */
 public function generate($data)
 {
     if ($data instanceof InfoProviderInterface) {
         $data = $data->getCacheKeyInfo();
     }
     if ($this->converter && !is_string($data)) {
         $convertedData = $this->converter->convert($data);
         if ($convertedData === false) {
             throw new InvalidArgumentException($data);
         }
         $data = $convertedData;
     } elseif (!is_string($data)) {
         throw new InvalidArgumentException($data);
     }
     $cacheKey = $this->normalizer->normalize($data);
     if ($this->prefix) {
         return $this->prefix . $cacheKey;
     }
     return $cacheKey;
 }
 /**
  * Manipulate document.
  *
  * @throws \Exception If a broken rule is executed and silent mode is not enabled.
  *
  * @return string
  */
 public function manipulate()
 {
     foreach ($this->rules as $rule) {
         try {
             $nodeList = $rule->query($this->document);
             foreach ($nodeList as $node) {
                 $rule->apply($node);
             }
         } catch (\Exception $e) {
             if (!$this->isSilentMode()) {
                 throw $e;
             }
         }
     }
     return $this->converter->toHtml($this->document);
 }
Пример #4
0
 /**
  * Method returns an array with configuration for specified tag in specified source.
  *
  * @param $tagName
  * @param $source
  * @return array
  */
 public function getConfig($tagName, $source)
 {
     $config = $this->reader->read($tagName, $source);
     return $this->converter->convert($config);
 }