public function testEasyPoXSD() { $filepath = dirname(__FILE__) . '/../../_files/EasyPO/'; $schema = simplexml_load_file($filepath . '/easypo.xsd'); $parser = new PiBX_CodeGen_SchemaParser(); $parser->setSchema($schema); $parsedTree = $parser->parse(); $namespaces = array('xs' => 'http://www.w3.org/2001/XMLSchema', 'po' => 'http://openuri.org/easypo'); $expectedTypeList = array(); $expectedType1 = new PiBX_AST_Type('purchase-order'); $expectedType1->setAsRoot(); $expectedType1->setTargetNamespace('http://openuri.org/easypo'); $expectedType1->setNamespaces($namespaces); $expectedType1->add(new PiBX_AST_TypeAttribute('customer', 'customer')); $expectedType1->add(new PiBX_AST_TypeAttribute('date', 'dateTime')); $ta = new PiBX_AST_TypeAttribute('line-item', 'line-item'); $ta->add(new PiBX_AST_CollectionItem('line-item', 'line-item')); $expectedType1->add($ta); $expectedType1->add(new PiBX_AST_TypeAttribute('shipper', 'shipper')); $expectedType2 = new PiBX_AST_Type('customer'); $expectedType2->add(new PiBX_AST_TypeAttribute('name', 'string')); $expectedType2->add(new PiBX_AST_TypeAttribute('address', 'string')); $ta = new PiBX_AST_TypeAttribute('age', 'int'); $ta->setStyle('attribute'); $expectedType2->add($ta); $ta = new PiBX_AST_TypeAttribute('moo', 'int'); $ta->setStyle('attribute'); $expectedType2->add($ta); $ta = new PiBX_AST_TypeAttribute('poo', 'int'); $ta->setStyle('attribute'); $expectedType2->add($ta); $expectedType3 = new PiBX_AST_Type('line-item'); $expectedType3->add(new PiBX_AST_TypeAttribute('description', 'string')); $expectedType3->add(new PiBX_AST_TypeAttribute('per-unit-ounces', 'decimal')); $expectedType3->add(new PiBX_AST_TypeAttribute('price', 'decimal')); $expectedType3->add(new PiBX_AST_TypeAttribute('quantity', 'integer')); $expectedType4 = new PiBX_AST_Type('shipper'); $expectedType4->add(new PiBX_AST_TypeAttribute('name', 'string')); $expectedType4->add(new PiBX_AST_TypeAttribute('per-ounce-rate', 'decimal')); $parser = new PiBX_CodeGen_SchemaParser(); $parser->setSchema($schema); $tree = $parser->parse(); $creator = new PiBX_CodeGen_ASTCreator(new PiBX_CodeGen_TypeUsage()); $tree->accept($creator); $typeList = $creator->getTypeList(); $this->assertEquals(4, count($typeList)); $this->assertEquals($expectedType1, $typeList[0]); $this->assertEquals($expectedType2, $typeList[1]); $this->assertEquals($expectedType3, $typeList[2]); $this->assertEquals($expectedType4, $typeList[3]); }
private function parseBinding(SimpleXMLElement $xml) { $nodes = $xml->xpath('/binding/mapping'); foreach ($nodes as $mapping) { $attributes = $mapping->attributes(); $name = (string) $attributes['name']; if ($name == '') { // abstract type? $name = (string) $attributes['type-name']; } $class = (string) $attributes['class']; $ast = new PiBX_AST_Type($name); $abstract = (string) $attributes['abstract']; if ($abstract !== 'true') { $ast->setAsRoot(); $ast->setTargetNamespace($this->getTargetNamespace()); } $ast->setType($class); $this->parseMapping($mapping, $ast); $this->asts[] = $ast; // update the ASTs if the current mapping is a referenced mapping. // i.e. an abstract mapping if (key_exists($name, $this->structuralReferences)) { $referencedName = $this->structuralReferences[$name]; $this->elementAsts[$referencedName] = $ast; } else { $this->elementAsts[$name] = $ast; } } }
function visitComplexTypeNode(PiBX_ParseTree_Tree $tree) { $this->plowTypesForLevel($tree->getLevel()); $logMessage = $tree->getLevel() . str_pad(" ", $tree->getLevel()) . " "; $logMessage .= "complex"; if ($tree->getLevel() == 0) { $logMessage .= " - global"; $t = new PiBX_AST_Type($tree->getName()); if ($this->countTypes() == 0) { // the first type is the XSD-root. $t->setAsRoot(); $t->setTargetNamespace($tree->getParent()->getTargetNamespace()); $t->setNamespaces($tree->getNamespaces()); } $sf = new PiBX_CodeGen_ASTStackFrame($tree->getLevel(), $t); array_push($this->stack, $sf); $this->typeUsage->addType($tree->getName()); } $this->log($logMessage); }