Beispiel #1
0
 public function generate(SchemaInterface $schema)
 {
     $this->_types = array();
     $html = $this->generateType($schema->getDefinition());
     // this makes sure that we only reference objects which are actually
     // rendered
     foreach ($this->_types as $typeId => $typeName) {
         $name = '<a href="#psx-type-' . $typeId . '">' . $typeName . '</a>';
         $html = preg_replace('/<a href=\\"#psx-type-' . $typeId . '\\">(\\w+)<\\/a>/ims', $name, $html);
     }
     return $html;
 }
Beispiel #2
0
 public function generate(SchemaInterface $schema)
 {
     $this->writer->startDocument('1.0', 'UTF-8');
     $this->writer->startElement('xs:schema');
     $this->writer->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
     $this->writer->writeAttribute('xmlns:tns', $this->targetNamespace);
     $this->writer->writeAttribute('targetNamespace', $this->targetNamespace);
     $this->writer->writeAttribute('elementFormDefault', 'qualified');
     // generate elements
     $this->generateRootElement($schema->getDefinition());
     $this->writer->endElement();
     $this->writer->endDocument();
     return $this->writer->outputMemory(true);
 }
Beispiel #3
0
 public function generate(SchemaInterface $schema)
 {
     $record = $this->generateType($schema->getDefinition(), $this->data);
     switch ($this->format) {
         case self::FORMAT_XML:
             $writer = new Writer\Xml();
             break;
         case self::FORMAT_JSON:
         default:
             $writer = new Writer\Json();
             break;
     }
     return $writer->write($record);
 }
Beispiel #4
0
 protected function getCollectionSchema(SchemaInterface $table)
 {
     $builder = new SchemaBuilder('collection');
     $builder->integer('startIndex');
     $builder->integer('count');
     $builder->integer('totalResults');
     $builder->arrayType('entry')->setPrototype($table->getDefinition());
     return new Schema($builder->getProperty());
 }
Beispiel #5
0
 public function generate(SchemaInterface $schema)
 {
     return Json::encode($this->generateRootElement($schema->getDefinition()), JSON_PRETTY_PRINT);
 }
Beispiel #6
0
 protected function assertParameters(SchemaInterface $parameters)
 {
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\IntegerType', $parameters->getDefinition()->get('param_integer'));
     $this->assertEquals(true, $parameters->getDefinition()->get('param_integer')->isRequired());
     $this->assertEquals(8, $parameters->getDefinition()->get('param_integer')->getMin());
     $this->assertEquals(16, $parameters->getDefinition()->get('param_integer')->getMax());
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\FloatType', $parameters->getDefinition()->get('param_number'));
     $this->assertEquals(false, $parameters->getDefinition()->get('param_number')->isRequired());
     $this->assertEquals('The number', $parameters->getDefinition()->get('param_number')->getDescription());
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\DateTimeType', $parameters->getDefinition()->get('param_date'));
     $this->assertEquals(false, $parameters->getDefinition()->get('param_date')->isRequired());
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\BooleanType', $parameters->getDefinition()->get('param_boolean'));
     $this->assertEquals(true, $parameters->getDefinition()->get('param_boolean')->isRequired());
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\StringType', $parameters->getDefinition()->get('param_string'));
     $this->assertEquals(false, $parameters->getDefinition()->get('param_string')->isRequired());
     $this->assertEquals(8, $parameters->getDefinition()->get('param_string')->getMinLength());
     $this->assertEquals(16, $parameters->getDefinition()->get('param_string')->getMaxLength());
     $this->assertEquals('[A-z]+', $parameters->getDefinition()->get('param_string')->getPattern());
     $this->assertEquals(['foo', 'bar'], $parameters->getDefinition()->get('param_string')->getEnumeration());
 }
Beispiel #7
0
 /**
  * Traverses through the data based on the provided schema and calls the
  * visitor methods. The type tells whether we going through incoming or
  * outgoing data. The traverser is for incoming data stricter then for
  * outgoing data
  *
  * @param mixed $data
  * @param \PSX\Data\SchemaInterface $schema
  * @param \PSX\Data\Schema\VisitorInterface $visitor
  * @param integer $type
  * @return mixed
  */
 public function traverse($data, SchemaInterface $schema, VisitorInterface $visitor, $type)
 {
     $this->pathStack = array();
     return $this->recTraverse($data, $schema->getDefinition(), $visitor, $type);
 }