Author: Victor Puertas (vpgugr@gmail.com)
示例#1
0
 /**
  * Collection matching of a item.
  *
  * @return \Yosymfony\Spress\Core\ContentManager\Collection\CollectionInterface
  */
 public function getCollectionForItem(ItemInterface $item)
 {
     foreach ($this->colectionItemCollection as $name => $collection) {
         $itemPath = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE) . '/';
         $collectionPath = $collection->getPath() . '/';
         if (strpos($itemPath, $collectionPath) === 0) {
             return $collection;
         }
     }
     return $this->colectionItemCollection->get('pages');
 }
示例#2
0
 /**
  * Sets an item.
  *
  * @param Yosymfony\Spress\Core\DataSource\ItemInterface
  *
  * @throws \RuntimeException If the item has been registered previously in another collection
  */
 public function set(ItemInterface $item)
 {
     $id = $item->getId();
     $collectionName = $item->getCollection();
     $this->items[$id] = $item;
     if (isset($this->idCollections[$id]) && $this->idCollections[$id] !== $collectionName) {
         throw new \RuntimeException(sprintf('The item with id: "%s" has been registered previously with another collection.', $id));
     }
     if (isset($this->itemCollections[$collectionName]) === false) {
         $this->itemCollections[$collectionName] = [];
     }
     $this->itemCollections[$collectionName][$id] = $item;
     $this->idCollections[$id] = $collectionName;
 }
示例#3
0
 /**
  * Gets the attributes of an item.
  *
  * @param ItemInterface $item
  *
  * @return array
  */
 protected function getItemAttributes(ItemInterface $item)
 {
     $result = $item->getAttributes();
     $result['id'] = $item->getId();
     $result['content'] = $item->getContent();
     $result['collection'] = $item->getCollection();
     $result['path'] = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);
     return $result;
 }
示例#4
0
 protected function isWritable(ItemInterface $item)
 {
     return $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT) === '' ? false : true;
 }
示例#5
0
 private function isRenderizerExcluded(ItemInterface $item)
 {
     $attributes = $item->getAttributes();
     if (array_key_exists('avoid_renderizer', $attributes) === false) {
         return false;
     }
     if (is_bool($attributes['avoid_renderizer']) === false) {
         throw new AttributeValueException('Invalid value. Expected bolean.', 'avoid_renderizer', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE));
     }
     return $attributes['avoid_renderizer'];
 }
示例#6
0
 protected function getAttributesResolver(ItemInterface $templateItem)
 {
     $resolver = new AttributesResolver();
     $resolver->setDefault('max_page', 5, 'int')->setDefault('provider', 'site.posts', 'string')->setDefault('permalink', '/page:num')->setDefault('sort_by', '', 'string')->setDefault('sort_type', 'descending', 'string')->setValidator('sort_type', function ($value) {
         switch ($value) {
             case 'descending':
             case 'ascending':
                 return true;
             default:
                 return false;
         }
     });
     $attributes = $templateItem->getAttributes();
     return $resolver->resolve($attributes);
 }
示例#7
0
 protected function getAttributesResolver(ItemInterface $templateItem)
 {
     $resolver = new AttributesResolver();
     $resolver->setDefault('taxonomy_attribute', 'categories', 'string')->setDefault('permalink', '/:name')->setDefault('pagination_permalink', '/page:num', 'string');
     $attributes = $templateItem->getAttributes();
     return $resolver->resolve($attributes);
 }
示例#8
0
 /**
  * Sets an include item.
  *
  * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item
  */
 public function setInclude(ItemInterface $item)
 {
     $this->includes[$item->getId()] = $item;
 }
示例#9
0
 /**
  * Converts an item. This method uses the SNAPSHOT_PATH_RELATIVE of Item path.
  *
  * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item The item
  *
  * @return Yosymfony\Spress\Core\ContentManager\Converter\ConverterResult
  *
  * @throws RuntimeException If there's no converter for the extension passed
  */
 public function convertItem(ItemInterface $item)
 {
     $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);
     $str = new StringWrapper($path);
     $extension = $str->getFirstEndMatch($this->textExtensions);
     if ($extension === '') {
         $extension = pathinfo($path, PATHINFO_EXTENSION);
     }
     return $this->convertContent($item->getContent(), $extension);
 }
示例#10
0
 private function getPermalinkAttribute(ItemInterface $item)
 {
     $attributes = $item->getAttributes();
     $permalink = isset($attributes['permalink']) ? $attributes['permalink'] : $this->defaultPermalink;
     if (is_string($permalink) === false) {
         throw new AttributeValueException('Invalid value. Expected string.', 'permalink', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE));
     }
     if (trim($permalink) === '') {
         throw new AttributeValueException('Invalid value. Expected a non-empty value.', 'permalink', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE));
     }
     return $permalink;
 }
示例#11
0
 protected function getAttributesResolver(ItemInterface $templateItem)
 {
     $resolver = new AttributesResolver();
     $resolver->setDefault('max_page', 5, 'int')->setDefault('provider', 'site.posts', 'string')->setDefault('permalink', '/page:num');
     $attributes = $templateItem->getAttributes();
     return $resolver->resolve($attributes);
 }
示例#12
0
 protected function getItemAttributes(ItemInterface $item)
 {
     $result = $item->getAttributes();
     $result['id'] = $item->getId();
     $result['content'] = $item->getContent();
     $result['collection'] = $item->getCollection();
     $result['path'] = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);
     $result['relationships'] = [];
     $relationships = $item->getRelationshipCollection();
     foreach ($relationships as $name => $items) {
         if (isset($result['relationships'][$name]) === false) {
             $result['relationships'][$name] = [];
         }
         foreach ($items as $relItem) {
             $relAttributes = $relItem->getAttributes();
             $relAttributes['id'] = $relItem->getId();
             $relAttributes['content'] = $relItem->getContent();
             $relAttributes['collection'] = $relItem->getCollection();
             $relAttributes['path'] = $relItem->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);
             $result['relationships'][$name][] = $relAttributes;
         }
     }
     return $result;
 }