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); }
private function sortItems() { $resolver = new AttributesResolver(); $resolver->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; } }); foreach ($this->CollectionManager->getCollectionItemCollection() as $collection) { $attributes = $resolver->resolve($collection->getAttributes()); if (empty($attributes['sort_by']) === true) { continue; } $sortBy = $attributes['sort_by']; $isDescending = $attributes['sort_type'] === 'descending'; $this->itemCollection->sortItems($sortBy, $isDescending, [$collection->getName()]); $this->setRelationships($collection->getName()); } }
/** * @expectedException \Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException */ public function testInvalidValue() { $a = new AttributesResolver(); $a->setDefault('port', 4000, 'int', false, false)->setValidator('port', function ($value) { return $value > 0 && $value <= 65535; }); $result = $a->resolve(['port' => -1]); }
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); }