diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..13cb6f8 --- /dev/null +++ b/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` diff --git a/src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php b/src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php index ada357b..29a8e6d 100755 --- a/src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php +++ b/src/ZfrRest/Mvc/Router/Http/ResourceGraphRoute.php @@ -83,7 +83,7 @@ public function __construct( $this->metadataFactory = $metadataFactory; $this->subPathMatcher = $matcher; $this->resource = $resource; - $this->route = trim($route, '/'); + $this->route = $route; } /** @@ -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) { @@ -157,14 +157,19 @@ 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()) { @@ -172,7 +177,7 @@ public function match(Request $request) } // 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; }