/**
  * @param AbstractPropertyFunctionNode $node
  * @return null|PropertyConfig
  */
 private function getPropertyConfigForNode(AbstractPropertyFunctionNode $node)
 {
     $name = $node->getNameOptionValue();
     $options = $node->getOptions();
     if ($node instanceof BlockPropertyListNode) {
         if (!isset($options['item'])) {
             throw new \RuntimeException(sprintf('Missing item definition for property list [%s] at line [%u].', $name, $node->getLine()));
         }
         if (!$options['item'] instanceof AbstractPropertyFunctionNode) {
             throw new \RuntimeException(sprintf('Item defined for property list [%s] at line [%u] is not a property.', $name, $node->getLine()));
         }
         $listConfig = $this->propertyMapper->createPropertyList($name, $node->getLabelOptionValue(), $this->getPropertyConfigForNode($options['item']));
         $node->setNode('arguments', new \Twig_Node());
         return $listConfig;
     } elseif ($node instanceof BlockPropertySetNode) {
         $setItems = array();
         if (!isset($options['items']) || !$options['items'] instanceof ArrayNode) {
             throw new \RuntimeException(sprintf('Missing items definition for property set [%s] at line [%u].', $name, $node->getLine()));
         }
         $items = $options['items'];
         /* @var $items ArrayNode */
         foreach ($items->getKeyValuePairs() as $i => $pair) {
             $itemNode = $pair['value'];
             if (!$itemNode instanceof AbstractPropertyFunctionNode) {
                 throw new \RuntimeException(sprintf('Item [%i] defined for property set [%s] at line [%u] is not a property.', $name, $node->getLine()));
             }
             $config = $this->getPropertyConfigForNode($itemNode);
             if ($config !== null) {
                 $setItems[$config->name] = $config;
             }
         }
         $setConfig = $this->propertyMapper->createPropertySet($name, $node->getLabelOptionValue(), $setItems);
         $node->setNode('arguments', new \Twig_Node());
         return $setConfig;
     } elseif ($node instanceof BlockPropertyNode) {
         $optionsArgumentNode = $node->getOptionsArgumentNode();
         if (!$optionsArgumentNode instanceof ArrayNode) {
             return null;
         }
         $constantOptions = $this->collectConstantValues($optionsArgumentNode);
         if (empty($constantOptions['type'])) {
             return null;
         }
         return $this->propertyMapper->createProperty($name, $constantOptions['type'], $constantOptions);
     } else {
         throw new \UnexpectedValueException();
     }
 }
Esempio n. 2
0
 protected function configureProperties(PropertyMapper $mapper)
 {
     $mapper->autoDiscover();
 }
Esempio n. 3
0
 protected function configureProperties(PropertyMapper $mapper)
 {
     $mapper->add('content', 'html');
 }