Beispiel #1
0
 public function onLoad()
 {
     parent::onLoad();
     $doc = $this->resourceListing->getDocumentation($this->context->get(Context::KEY_PATH));
     if (!$doc instanceof DocumentationInterface) {
         throw new RuntimeException('No documentation available');
     }
     $this->version = $this->getVersion($doc);
     $this->resource = $this->getResource($doc, $this->version);
     if (!$this->resource->hasMethod($this->getMethod())) {
         throw new StatusCode\MethodNotAllowedException('Method is not allowed', $this->resource->getAllowedMethods());
     }
     $this->pathParameters = $this->schemaAssimilator->assimilate($this->resource->getPathParameters(), $this->uriFragments);
     $this->queryParameters = $this->schemaAssimilator->assimilate($this->resource->getMethod($this->getMethod())->getQueryParameters(), $this->request->getUri()->getParameters());
 }
Beispiel #2
0
 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'));
 }