Skip to content

Commit

Permalink
API index now contains information about globally supported mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Jun 23, 2015
1 parent 1a42163 commit bd4f108
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
6.2.1 (2015-06-23)
------------------

* API index now contains information about globally supported mime types


6.2.0 (2015-06-17)
------------------

Expand Down
5 changes: 3 additions & 2 deletions src/main/php/routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,18 @@ public function shouldBeIgnoredInApiIndex()
* returns route as resource
*
* @param \stubbles\peer\http\HttpUri $uri
* @param string[] $globalMimeTypes list of globally supported mime types
* @return \stubbles\webapp\routing\api\Resource
* @since 6.1.0
*/
public function asResource(HttpUri $uri)
public function asResource(HttpUri $uri, array $globalMimeTypes = [])
{
$routeUri = $uri->withPath($this->normalizePath());
return new Resource(
$this->resourceName(),
$this->allowedRequestMethods,
$this->requiresHttps() ? $routeUri->toHttps() : $routeUri,
$this->supportedMimeTypes()->asArray(),
$this->supportedMimeTypes($globalMimeTypes)->asArray(),
$this->routingAnnotations(),
$this->authConstraint()
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/routing/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function passThroughOnGet(
*/
public function apiIndexOnGet($path)
{
return $this->onGet($path, new Index($this->routes));
return $this->onGet($path, new Index($this->routes, $this->mimeTypes));
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/main/php/routing/api/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ class Index implements Target
* @type \stubbles\webapp\routing\Routes
*/
private $routes;
/**
* @type string[]
*/
private $globalMimeTypes;

/**
* constructor
*
* @param \stubbles\webapp\routing\Routes $routes
* @param \stubbles\webapp\routing\Routes $routes list of available routes
* @param string[] $globalMimeTypes list of globally supported mime types
*/
public function __construct(Routes $routes)
public function __construct(Routes $routes, array $globalMimeTypes)
{
$this->routes = $routes;
$this->routes = $routes;
$this->globalMimeTypes = $globalMimeTypes;
}

/**
Expand All @@ -54,7 +60,7 @@ public function resolve(Request $request, Response $response, UriPath $uriPath)
foreach ($this->routes as $route) {
/* @var $route \stubbles\webapp\routing\Route */
if (!$route->shouldBeIgnoredInApiIndex()) {
$resources->add($route->asResource($uri));
$resources->add($route->asResource($uri, $this->globalMimeTypes));
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/php/routing/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,30 @@ public function resourceRepresentationContainsListOfSupportedMimeTypes()
);
}

/**
* @test
* @since 6.2.1
*/
public function resourceRepresentationContainsListOfSupportedMimeTypesIncludingGlobal()
{
$route = new Route(
'/orders/?$',
'stubbles\webapp\routing\AnnotatedProcessor',
'GET'
);
$route->supportsMimeType('application/xml');
assertEquals(
['text/plain',
'application/bar',
'application/baz',
'application/xml',
'application/foo'
],
$route->asResource(HttpUri::fromString('http://example.com/'), ['application/foo'])
->mimeTypes()
);
}

/**
* @test
* @since 6.1.0
Expand Down

0 comments on commit bd4f108

Please sign in to comment.