resolve() public method

If an attribute is marked as nullable the validate function never will be invoked.
public resolve ( array $attributes ) : array
$attributes array
return array The merged and validated options
Example #1
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);
 }
Example #2
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);
 }
Example #3
0
 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]);
 }
Example #5
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);
 }