Skip to content

Commit

Permalink
Merge ae5d8c4 into 99ba9e3
Browse files Browse the repository at this point in the history
  • Loading branch information
Thinkscape committed Nov 14, 2013
2 parents 99ba9e3 + ae5d8c4 commit c00225d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
36 changes: 36 additions & 0 deletions UPGRADE.md
@@ -0,0 +1,36 @@
# UPGRADE GUIDE

## 1.0.0 (voltaire)

* `@REST\Association` has been renamed to `@REST\ExposedAssociation`
* Routing changes
* Router can now be used in child-routes.
* Routes of type `ResourceGraphRoute` **must not** contain a literal prefix.
* For example, this route is invalid: `/api/v3/data/users` (it will never match)
* Static (literal) parts of the route **must** now be defined separately as part of parent route, for example:

````php
// routes => array(
// this will work with: /api/v3/data/users
'rest-data' => array(
'type' => 'Literal',
'options' => array(
'route' => '/api/v3/data'
),
'child_routes' => array(
'users' => array(
'type' => 'ResourceGraphRoute',
'options' => array(
'route' => '/users',
'resource' => 'Application\Repository\UserRepository'
)
),
)
)
````

* Configuration changes
* `resource_metadata` key is now removed and all sub-keys have been moved to the main configuration array
(i.e. `[zfr_rest][resource_metadata][cache]` becomes `[zfr_rest][cache]`
* `cache` now expects a name of a service which will be loaded from ServiceManager. The service must
implement `Metadata\Cache\CacheInterface`
21 changes: 13 additions & 8 deletions src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php
Expand Up @@ -83,7 +83,7 @@ public function __construct(
$this->metadataFactory = $metadataFactory;
$this->subPathMatcher = $matcher;
$this->resource = $resource;
$this->route = trim($route, '/');
$this->route = $route;
}

/**
Expand All @@ -99,16 +99,16 @@ public function __construct(
* - assemble(array(1, 'tweets' => 1)): returns "/users/1/tweets/1"
* - assemble(array(1, 'tweets' => 1, 'retweets')): returns "/users/1/tweets/1/retweets"
*
* As you can see, order or params matters!
* As you can see, order of params matters!
*
* Note that this method won't perform any database calls for performance reasons. It just checks
* that associations exist
* if associations exist.
*
* {@inheritDoc}
*/
public function assemble(array $params = array(), array $options = array())
{
$url = $this->route;
$url = trim($this->route, '/');
$resourceMetadata = $this->getResource()->getMetadata();

foreach ($params as $key => $value) {
Expand Down Expand Up @@ -157,22 +157,27 @@ public static function factory($options = array())
/**
* {@inheritDoc}
*/
public function match(Request $request)
public function match(Request $request, $pathOffset = null, array $options = array())
{
if (!$request instanceof HttpRequest) {
return null;
}

$uri = $request->getUri();
$path = trim($uri->getPath(), '/');
$route = trim($this->route, '/');
$uri = $request->getUri();
if ($pathOffset === null) {
$path = trim($uri->getPath(), '/');
}else{
$path = trim(substr($uri->getPath(), $pathOffset), '/');
}

// We must omit the basePath
if (method_exists($request, 'getBaseUrl') && $baseUrl = $request->getBaseUrl()) {
$path = substr($path, strlen(trim($baseUrl, '/')));
}

// If the URI does not begin by the route, we can stop immediately
if (substr($path, 0, strlen($this->route)) !== $this->route) {
if (substr($path, 0, strlen($route)) !== $route) {
return null;
}

Expand Down

0 comments on commit c00225d

Please sign in to comment.