コード例 #1
0
ファイル: Property.php プロジェクト: seytar/psx
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('a');
     $sb->string('foo');
     $complexA = $sb->getProperty();
     $sb = $this->getSchemaBuilder('b');
     $sb->string('bar');
     $complexB = $sb->getProperty();
     $choice = SchemaProperty::getChoice("choice")->add($complexA)->add($complexB);
     $sb = $this->getSchemaBuilder('complex');
     $sb->string('foo');
     $complex = $sb->getProperty();
     $sb = $this->getSchemaBuilder('property');
     $sb->arrayType('array')->setPrototype(SchemaProperty::getString('foo'));
     $sb->arrayType('arrayComplex')->setPrototype($complex);
     $sb->arrayType('arrayChoice')->setPrototype($choice);
     $sb->boolean('boolean');
     $sb->choiceType($choice);
     $sb->complexType($complex);
     $sb->date('date');
     $sb->dateTime('dateTime');
     $sb->duration('duration');
     $sb->float('float');
     $sb->integer('integer');
     $sb->string('string');
     $sb->time('time');
     return $sb->getProperty();
 }
コード例 #2
0
ファイル: TestSchema.php プロジェクト: seytar/psx
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('location')->setDescription('Location of the person');
     $sb->integer('lat');
     $sb->integer('long');
     $location = $sb->getProperty();
     $sb = $this->getSchemaBuilder('web')->setDescription('An application');
     $sb->string('name');
     $sb->string('url');
     $web = $sb->getProperty();
     $sb = $this->getSchemaBuilder('author')->setDescription('An simple author element with some description');
     $sb->string('title')->setPattern('[A-z]{3,16}')->setRequired(true);
     $sb->string('email')->setDescription('We will send no spam to this addresss');
     $sb->arrayType('categories')->setPrototype(Property::getString('category'))->setMaxLength(8);
     $sb->arrayType('locations')->setPrototype($location)->setDescription('Array of locations');
     $sb->complexType('origin', $location);
     $author = $sb->getProperty();
     $sb = $this->getSchemaBuilder('news')->setDescription('An general news entry');
     $sb->arrayType('tags')->setPrototype(Property::getString('tag'))->setMinLength(1)->setMaxLength(6);
     $sb->arrayType('receiver')->setPrototype($author)->setMinLength(1)->setRequired(true);
     $sb->arrayType('resources')->setPrototype(Property::getChoice('resource')->add($location)->add($web));
     $sb->boolean('read');
     $sb->choiceType('source')->add($author)->add($web);
     $sb->complexType($author)->setRequired(true);
     $sb->date('sendDate');
     $sb->dateTime('readDate');
     $sb->duration('expires');
     $sb->float('price')->setMin(1)->setMax(100)->setRequired(true);
     $sb->integer('rating')->setMin(1)->setMax(5);
     $sb->string('content')->setDescription('Contains the main content of the news entry')->setMinLength(3)->setMaxLength(512)->setRequired(true);
     $sb->string('question')->setEnumeration(array('foo', 'bar'));
     $sb->time('coffeeTime');
     return $sb->getProperty();
 }
コード例 #3
0
ファイル: VersionViewController.php プロジェクト: seytar/psx
 public function getDocumentation()
 {
     $doc = new Documentation\Version();
     $resource = new Resource(Resource::STATUS_CLOSED, $this->context->get(Context::KEY_PATH));
     $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection')));
     $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $doc->addResource(1, $resource);
     $resource = new Resource(Resource::STATUS_DEPRECATED, $this->context->get(Context::KEY_PATH));
     $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection')));
     $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $doc->addResource(2, $resource);
     $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH));
     $resource->setTitle('foo');
     $resource->setDescription('lorem ipsum');
     $resource->addPathParameter(Property::getString('name')->setDescription('Name parameter')->setRequired(false)->setMinLength(0)->setMaxLength(16)->setPattern('[A-z]+'));
     $resource->addPathParameter(Property::getString('type')->setEnumeration(['foo', 'bar']));
     $resource->addMethod(Resource\Factory::getMethod('GET')->setDescription('Returns a collection')->addQueryParameter(Property::getInteger('startIndex')->setDescription('startIndex parameter')->setRequired(false)->setMin(0)->setMax(32))->addQueryParameter(Property::getFloat('float'))->addQueryParameter(Property::getBoolean('boolean'))->addQueryParameter(Property::getDate('date'))->addQueryParameter(Property::getDateTime('datetime'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection')));
     $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage')));
     $doc->addResource(3, $resource);
     return $doc;
 }
コード例 #4
0
ファイル: Schema.php プロジェクト: seytar/psx
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('person');
     $sb->setReference('PSX\\Data\\Record\\Importer\\Test\\Person');
     $sb->string('title')->setRequired(true);
     $person = $sb->getProperty();
     $sb = $this->getSchemaBuilder('entry');
     $sb->setReference('PSX\\Data\\Record\\Importer\\Test\\Entry');
     $sb->string('title')->setRequired(true);
     $entry = $sb->getProperty();
     $sb = $this->getSchemaBuilder('token');
     $sb->setReference('PSX\\Data\\Record\\Importer\\Test\\Factory');
     $sb->string('alg')->setRequired(true);
     $sb->string('sig')->setRequired(true);
     $token = $sb->getProperty();
     $sb = $this->getSchemaBuilder('news');
     $sb->integer('id')->setRequired(true);
     $sb->string('title')->setPattern('[A-z]{3,16}')->setRequired(true);
     $sb->boolean('active')->setRequired(true);
     $sb->boolean('disabled')->setRequired(true);
     $sb->integer('count')->setEnumeration(array(6, 12))->setRequired(true);
     $sb->float('rating')->setMin(8)->setMax(14)->setRequired(true);
     $sb->dateTime('date')->setRequired(true);
     $sb->complexType($person);
     $sb->arrayType('tags')->setPrototype(Property::getString('tag'))->setMinLength(0)->setMaxLength(4);
     $sb->arrayType('entry')->setPrototype($entry);
     $sb->complexType($token);
     $sb->string('url')->setReference('PSX\\Url')->setRequired(true);
     return $sb->getProperty();
 }
コード例 #5
0
ファイル: ArrayTypeTest.php プロジェクト: seytar/psx
 public function testGetId()
 {
     $property = Property::getArray('test');
     $this->assertEquals('79db27401a9ee86ee36d6c38ba1cd653', $property->getId());
     $property = Property::getArray('test');
     $property->setPrototype(Property::getString('foo'));
     $this->assertEquals('b2968af7bc5a42f395857827093d77f6', $property->getId());
 }
コード例 #6
0
ファイル: Action.php プロジェクト: virusvn/fusio
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('action');
     $sb->integer('id');
     $sb->string('name')->setPattern('[A-z0-9\\-\\_]{3,64}');
     $sb->string('class');
     $sb->anyType('config')->setPrototype(Property::getString('value'));
     return $sb->getProperty();
 }
コード例 #7
0
ファイル: ComplexTypeTest.php プロジェクト: seytar/psx
 public function testProperties()
 {
     $property = Property::getComplex('test')->add(Property::getString('foo'))->add(Property::getString('bar'));
     $this->assertInstanceOf('PSX\\Data\\Schema\\Property\\StringType', $property->get('foo'));
     $this->assertTrue($property->has('foo'));
     $property->remove('foo');
     $property->remove('foo');
     // should not produce an error
     $this->assertFalse($property->has('foo'));
 }
コード例 #8
0
ファイル: User.php プロジェクト: uqiauto/fusio
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('user');
     $sb->integer('id');
     $sb->integer('status');
     $sb->string('name')->setPattern('[A-z0-9\\-\\_\\.]{3,32}');
     $sb->arrayType('scopes')->setPrototype(Property::getString('name'));
     $sb->arrayType('apps')->setPrototype($this->getSchema('Fusio\\Impl\\Backend\\Schema\\App'));
     $sb->dateTime('date');
     return $sb->getProperty();
 }
コード例 #9
0
ファイル: App.php プロジェクト: virusvn/fusio
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('app');
     $sb->integer('id');
     $sb->integer('userId');
     $sb->integer('status');
     $sb->string('name')->setPattern('[A-z0-9\\-\\_]{3,64}');
     $sb->string('url');
     $sb->string('appKey');
     $sb->string('appSecret');
     $sb->arrayType('scopes')->setPrototype(Property::getString('name'));
     $sb->arrayType('tokens')->setPrototype($this->getSchema('Fusio\\Backend\\Schema\\App\\Token'));
     return $sb->getProperty();
 }
コード例 #10
0
ファイル: MethodAbstractTest.php プロジェクト: seytar/psx
 public function testMethod()
 {
     $method = Factory::getMethod('POST');
     $method->setDescription('foobar');
     $method->addQueryParameter(Property::getString('foo'));
     $method->setRequest(new Schema(Property::getString('foo')));
     $method->addResponse(200, new Schema(Property::getString('foo')));
     $this->assertEquals('foobar', $method->getDescription());
     $this->assertInstanceOf('PSX\\Data\\SchemaInterface', $method->getQueryParameters());
     $this->assertTrue($method->hasRequest());
     $this->assertInstanceOf('PSX\\Data\\SchemaInterface', $method->getRequest());
     $this->assertInstanceOf('PSX\\Data\\SchemaInterface', $method->getResponse(200));
     $this->assertTrue($method->hasResponse(200));
     $this->assertFalse($method->hasResponse(201));
 }
コード例 #11
0
ファイル: ResourceTest.php プロジェクト: seytar/psx
 public function testResource()
 {
     $resource = new Resource(Resource::STATUS_ACTIVE, '/foo');
     $resource->setTitle('foobar');
     $resource->setDescription('foobar');
     $resource->addPathParameter(Property::getString('foo'));
     $resource->addMethod(Factory::getMethod('GET'));
     $this->assertEquals(Resource::STATUS_ACTIVE, $resource->getStatus());
     $this->assertTrue($resource->isActive());
     $this->assertFalse($resource->isDeprecated());
     $this->assertFalse($resource->isClosed());
     $this->assertEquals('/foo', $resource->getPath());
     $this->assertEquals('foobar', $resource->getTitle());
     $this->assertEquals('foobar', $resource->getDescription());
     $this->assertInstanceOf('PSX\\Data\\SchemaInterface', $resource->getPathParameters());
     $this->assertInstanceOf('PSX\\Api\\Resource\\MethodAbstract', $resource->getMethod('GET'));
     $this->assertEquals(['GET' => $resource->getMethod('GET')], $resource->getMethods());
     $this->assertEquals(['GET'], $resource->getAllowedMethods());
     $this->assertTrue($resource->hasMethod('GET'));
     $this->assertFalse($resource->hasMethod('POST'));
 }
コード例 #12
0
ファイル: Raml.php プロジェクト: seytar/psx
 protected function getPropertyType($type, $name)
 {
     switch ($type) {
         case 'integer':
             return Property::getInteger($name);
         case 'number':
             return Property::getFloat($name);
         case 'date':
             return Property::getDateTime($name);
         case 'boolean':
             return Property::getBoolean($name);
         case 'string':
         default:
             return Property::getString($name);
     }
 }
コード例 #13
0
ファイル: Document.php プロジェクト: seytar/psx
 protected function parseString(array $data, $name)
 {
     $property = null;
     if (isset($data['format'])) {
         if ($data['format'] == 'date') {
             $property = Property::getDate($name);
         } elseif ($data['format'] == 'date-time') {
             $property = Property::getDateTime($name);
         } elseif ($data['format'] == 'duration') {
             $property = Property::getDuration($name);
         } elseif ($data['format'] == 'time') {
             $property = Property::getTime($name);
         }
     }
     if ($property === null) {
         $property = Property::getString($name);
     }
     $this->parseScalar($property, $data);
     return $property;
 }
コード例 #14
0
ファイル: AssimilatorTest.php プロジェクト: seytar/psx
 public function getDefinition()
 {
     $sb = $this->getSchemaBuilder('location');
     $sb->string('lat');
     $sb->string('long');
     $location = $sb->getProperty();
     $sb = $this->getSchemaBuilder('author');
     $sb->string('title');
     $sb->string('email');
     $sb->complexType($location);
     $author = $sb->getProperty();
     $sb = $this->getSchemaBuilder('news');
     $sb->string('content')->setRequired(true);
     $sb->integer('rating');
     $sb->float('price');
     $sb->boolean('read');
     $sb->complexType($location);
     $sb->arrayType('receiver')->setPrototype($author);
     $sb->arrayType('tags')->setPrototype(Property::getString('tag'));
     $sb->date('date');
     return $sb->getProperty();
 }
コード例 #15
0
 /**
  * @expectedException \ErrorException
  */
 public function testVisitStringInvalidFormat()
 {
     $visitor = new AssimilationVisitor();
     $property = Property::getString('test');
     $visitor->visitString(array(), $property, '');
 }
コード例 #16
0
ファイル: ValidationVisitorTest.php プロジェクト: seytar/psx
 public function testVisitStringNull()
 {
     $visitor = new ValidationVisitor();
     $property = Property::getString('test');
     $this->assertTrue($visitor->visitString(null, $property, ''));
 }
コード例 #17
0
ファイル: StringTypeTest.php プロジェクト: seytar/psx
 public function testGetTypeName()
 {
     $this->assertEquals('string', Property::getString('test')->getTypeName());
 }