/** * 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'); }
/** * 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; }
/** * 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; }
protected function isWritable(ItemInterface $item) { return $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT) === '' ? false : true; }
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']; }
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); }
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); }
/** * Sets an include item. * * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item */ public function setInclude(ItemInterface $item) { $this->includes[$item->getId()] = $item; }
/** * 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); }
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; }
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); }
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; }