function getChildElementByComplexTypeName($complexTypeName, $vocabulary, $prefix){ $app = \Slim\Slim::getInstance(); $filePath = $app->config('schemaPath') . $vocabulary . '.' . $prefix['extension']; $xml = file_get_contents( $filePath ); $xmlObject = simplexml_load_string( $xml ); $namespace = 'xsd'; if($vocabulary == 'xsd'){ $namespace = 'xs'; } $children = $xmlObject->children( $namespace, true ); $propertyElements = $children->element; $temp = array(); $temp['element'] = array(); foreach ( $children->complexType as $value ) { if ( (string) $value->attributes()->name != $complexTypeName ) { continue; } $temp['name'] = (string) $value->attributes()->name; if(isset($value->complexContent->extension)){ $extensionName = $value->complexContent->extension->attributes()->base; $extensionChildElements = getChildElementByComplexTypeName(str_replace($vocabulary . ":", "", $extensionName), $vocabulary, $prefix); if(!empty($extensionChildElements['element'])){ $temp['element'] = array_merge($temp['element'],$extensionChildElements['element']); } } if ( ! empty( $value->complexContent ) && isset($value->complexContent->extension->sequence->group)) { $groupRef = str_replace('ic:', '', $value->complexContent->extension->sequence->group->attributes()->ref); $elements = null; foreach ( $children->group as $group ) { if ( (string) $group->attributes()->name === $groupRef ) { $elements = $group->sequence->element; break; } } if(is_object($elements)){ foreach ( (object) $elements as $element ) { $ref = (string) $element->attributes()->ref; $type = null; foreach ( $propertyElements as $propertyElement ) { $name = str_replace($vocabulary . ":", '', $ref); if((string) $propertyElement->attributes()->name == $name){ $type = (string) $propertyElement->attributes()->type; break; } } if(strpos($type, '単純型')){ foreach ( $children->simpleType as $simpleType ) { if ( (string) $simpleType->attributes()->name === str_replace('ic:', '', $type) ) { $type = (string) $simpleType->restriction->attributes()->base; break; } } } $temp['element'][] = array( 'name' => $ref, 'type' => $type ); } } } elseif ( ! empty( $value->simpleContent ) ) { foreach ( (object) $value->simpleContent->extension->attribute as $attribute ) { $type = (string) $attribute->attributes()->type; $temp['element'][] = $type; } } } return $temp; }
} $prefix = $app->config('prefix')[$vocabulary]; $filePath = $app->config('schemaPath') . $vocabulary . '.' . $prefix['extension']; $xml = file_get_contents($filePath); $xmlObject = simplexml_load_string($xml); $children = $xmlObject->children('xsd', true); $elementName = str_replace($vocabulary . ":", "", $ic); $elementType = null; foreach ($children->element as $value) { if ((string) $value->attributes()->name != $elementName) { continue; } $elementType = $value->attributes()->type; } $complexTypeName = str_replace($vocabulary . ":", "", $elementType); $results = getChildElementByComplexTypeName($complexTypeName, $vocabulary, $prefix); $app->response->headers->set('Content-Type', 'application/json'); $app->response->write(json_encode($results)); }); $app->get('/:vocabulary', function ($vocabulary = null) use($app) { if (!$vocabulary || !array_key_exists($vocabulary, $app->config('prefix'))) { return false; } $prefix = $app->config('prefix')[$vocabulary]; $filePath = $app->config('schemaPath') . $vocabulary . '.' . $prefix['extension']; $results = array(); if ($prefix['extension'] == 'xsd') { $xml = file_get_contents($filePath); $xmlObject = simplexml_load_string($xml); $namespace = 'xsd'; if ($vocabulary == 'xsd') {