Exemplo n.º 1
0
 private static function getAttributeMeta(SimpleXMLElement $element)
 {
     $token = new VariableTokenMetaData(self::getTokenValue($element->Token_variable_name));
     $attributeMeta = new AttributeMetaData();
     $attributeMeta->setToken($token);
     $tokenDef = null;
     $tokenMeta = null;
     $metaDataClass = null;
     $isArray = false;
     if (property_exists($element, StringAttributeMetaData::NODE_NAME)) {
         $tokenDef = $element->Token_string;
         $metaDataClass = 'StringAttributeMetaData';
     }
     if (strcasecmp($element->getName(), StringAttributeMetaData::NODE_NAME) === 0) {
         $tokenDef = $element;
         $metaDataClass = 'StringAttributeMetaData';
     }
     if (property_exists($element, IntegerAttributeMetaData::NODE_NAME)) {
         $tokenDef = $element->Token_int;
         $metaDataClass = 'IntegerAttributeMetaData';
     }
     if (strcasecmp($element->getName(), IntegerAttributeMetaData::NODE_NAME) === 0) {
         $tokenDef = $element;
         $metaDataClass = 'IntegerAttributeMetaData';
     }
     if (property_exists($element, BooleanAttributeMetaData::NODE_NAME)) {
         $tokenDef = $element->Token_bool;
         $metaDataClass = 'BooleanAttributeMetaData';
     }
     if (strcasecmp($element->getName(), BooleanAttributeMetaData::NODE_NAME) === 0) {
         $tokenDef = $element;
         $metaDataClass = 'BooleanAttributeMetaData';
     }
     if (property_exists($element, RealAttributeMetaData::NODE_NAME)) {
         $tokenDef = $element->Token_real;
         $metaDataClass = 'RealAttributeMetaData';
     }
     if (strcasecmp($element->getName(), RealAttributeMetaData::NODE_NAME) === 0) {
         $tokenDef = $element;
         $metaDataClass = 'RealAttributeMetaData';
     }
     if (property_exists($element, ArrayAttributeMetaData::NODE_NAME)) {
         $tokenDef = $element->AST_array;
         $metaDataClass = 'ArrayAttributeMetaData';
         $isArray = true;
     }
     if (strcasecmp($element->getName(), ArrayAttributeMetaData::NODE_NAME) === 0) {
         $tokenDef = $element;
         $metaDataClass = 'ArrayAttributeMetaData';
         $isArray = true;
     }
     if ($metaDataClass === null) {
         $attributeMeta->setAttributeValue(new NopAttributeValueMetaData());
         return $attributeMeta;
     }
     // TODO: metaDataクラスを探すまでが長い
     $tokenMeta = new $metaDataClass((string) $tokenDef->source_rep);
     if ($isArray) {
         $tokenMeta = new ArrayAttributeMetaData();
         $list = new ArrayElementMetaDataList();
         foreach ($tokenDef->AST_array_elem_list as $elementList) {
             $elements = $elementList->children();
             foreach ($elements as $key => $e) {
                 if (strcasecmp($key, ArrayElementMetaData::NODE_NAME) !== 0) {
                     continue;
                 }
                 $children = (array) $e;
                 if (array_key_exists('AST_expr', $children)) {
                     $meta = self::getAttributeMeta($e);
                     $meta->getToken()->setValue('value');
                     $list->add(new ArrayElementMetaData($meta));
                 } else {
                     if (3 === count($children)) {
                         foreach ($children as $k => $child) {
                             if (!in_array($k, self::$acceptTokenNodes, true)) {
                                 continue;
                             }
                             $keyToken = self::getAttributeMeta($child[0]);
                             $valueToken = self::getAttributeMeta($child[1]);
                             $keyToken->getToken()->setValue('key');
                             $valueToken->getToken()->setValue('value');
                             $list->add(new ArrayHashElementMetaData($keyToken, $valueToken));
                         }
                     } else {
                         $tokens = array();
                         foreach ($children as $k => $child) {
                             if (!in_array($k, self::$acceptTokenNodes, true)) {
                                 continue;
                             }
                             $tokens[] = self::getAttributeMeta($child);
                         }
                         $tokens[0]->getToken()->setValue('key');
                         $tokens[1]->getToken()->setValue('value');
                         $list->add(new ArrayHashElementMetaData($tokens[0], $tokens[1]));
                     }
                 }
             }
         }
         $tokenMeta->setElementList($list);
     }
     if ($tokenDef !== null && $tokenMeta !== null) {
         $attributeMeta->setAttributeValue(new AttributeValueMetaData($tokenMeta));
     } else {
         $attributeMeta->setAttributeValue(new NopAttributeValueMetaData());
     }
     return $attributeMeta;
 }
Exemplo n.º 2
0
 public function visitArrayElementListMeta(ArrayElementMetaDataList $meta)
 {
     $buf = new TreeOutput();
     $buf->add('[' . $meta->getNodeName() . ']');
     $buf->down();
     $list = $meta->getList();
     foreach ($list as $arrayElement) {
         $buf->writeln($arrayElement->toJSValue($this));
     }
     $buf->up();
     return $buf;
 }