Skip to content

Commit e27d31f

Browse files
committed
Merge pull request #184 from zf-fr/refactor
[WIP] ZfrRest NEXT
2 parents 9571d61 + b09fb45 commit e27d31f

File tree

173 files changed

+2031
-9825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2031
-9825
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.4
54
- 5.5
65
- 5.6
76

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 0.4.0
4+
5+
* Complete rewrite of ZfrRest. All the concepts have been changed in favour of an explicit module, please read the
6+
new docs.
7+
* PHP dependency has been raised to PHP 5.5
8+
39
## 0.3.4
410

511
* ZfrRest now supports coalesce filtering for "hasMany" or "findMany" requests type through the new, optional

Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* It allows usage of this module even without composer.
66
* The original Module.php is in 'src/ZfrRest' in order to respect PSR-0
77
*/
8-
require_once __DIR__ . '/src/ZfrRest/Module.php';
8+
require_once __DIR__ . '/src/Module.php';

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,38 @@ ZfrRest
88
[![Total Downloads](https://poser.pugx.org/zfr/zfr-rest/downloads.png)](https://packagist.org/packages/zfr/zfr-rest)
99
[![Dependency Status](https://www.versioneye.com/package/php--zfr--zfr-rest/badge.png)](https://www.versioneye.com/package/php--zfr--zfr-rest)
1010

11-
> If you are an Ember Data user, I have created a specific renderer that output JSON compliant payload. I didn't
12-
released it yet as it's not really clean, but if you're interested, please contact me :).
13-
1411
## Installation
1512

1613
Install the module by typing (or add it to your `composer.json` file):
1714

18-
`php composer.phar require zfr/zfr-rest:0.3.*`
15+
`php composer.phar require zfr/zfr-rest:0.4.*`
1916

2017
Then, add the keys "ZfrRest" to your modules list in `application.config.php` file, and copy-paste the file
2118
`zfr_rest.global.php.dist` into your `autoload` folder (don't forget to remove the .dist extension at the end!).
2219

20+
## ZfrRest 0.4+ vs ZfrRest 0.3
21+
22+
Starting from version 0.4, ZfrRest has been completely rewritten from scratch. Previously, ZfrRest used to do a lot
23+
of things automatically for you, from rendering, to automatic routing and creation of routes. However, while nice for
24+
very simple use cases, it was actually very hard to extend, introduced a lot of performance problems and was quite
25+
unflexible.
26+
27+
Now, ZfrRest is more a "small REST utility". It provides a simple way to handle HTTP exceptions, a lightweight
28+
controller that can both handle action and HTTP verbs, and a view layer adapted for resource rendering (that can
29+
optionally use versioning to render a resource differently based on the version). You can consider ZfrRest as a
30+
module that you can use if you want to create a REST API, instead of a full-blown module like Apigility or previous
31+
ZfrRest versions.
32+
33+
Additionally, dependency to Doctrine has been completely remove and can be used by anyone.
34+
2335
## ZfrRest vs Apigility
2436

2537
[Apigility](http://www.apigility.org) is a Zend Framework 2 API builder that also aims to simplify the creation of
2638
REST APIs.
2739

28-
ZfrRest and Apigility philosophies are completely different. ZfrRest is Doctrine only, and focuses only on a very
29-
small subset on your REST API: it provides routing, validation and hydration.
30-
31-
On the other hand, Apigility comes with a graphical user interface, versioning support, authorization, authentication
32-
HAL, content negotiation... ZfrRest will never provide **all** those functionalities, so if you need them, just go
33-
with Apigility.
34-
35-
ZfrRest's scope is much more limited (although I'd really like to add support for versioning and links), but I
36-
really think it's a nice product too. So give it a try to both products, and choose the one you prefer!
40+
Starting from ZfrRest 0.4+, there is actually nothing in common between those two libraries. Apigility is a full-blown
41+
module that does a lot of things, from headers negotiation, automatic rendering, link generation, a code-generator...
42+
On the other hand, ZfrRest is the bare metal, and leave most of the responsability and power to you.
3743

3844
## Documentation
3945

composer.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
],
2626
"minimum-stability": "beta",
2727
"require": {
28-
"php": ">=5.4",
29-
"jms/metadata": "~1.5",
30-
"doctrine/common": "~2.4",
31-
"doctrine/doctrine-module": "~0.8",
32-
"zendframework/zend-cache": "~2.2",
28+
"php": ">=5.5",
3329
"zendframework/zend-http": "~2.2",
3430
"zendframework/zend-inputfilter": "~2.2",
3531
"zendframework/zend-mvc": "~2.2",
@@ -41,14 +37,17 @@
4137
},
4238
"require-dev": {
4339
"zendframework/zendframework": "~2.2",
44-
"doctrine/doctrine-orm-module": "~0.8",
45-
"phpunit/phpunit": "~3.7",
46-
"squizlabs/php_codesniffer": "1.4.*",
47-
"satooshi/php-coveralls": "~0.6"
40+
"phpunit/phpunit": "~4.1",
41+
"squizlabs/php_codesniffer": "1.4.*"
4842
},
4943
"autoload": {
50-
"psr-0": {
44+
"psr-4": {
5145
"ZfrRest\\": "src/"
5246
}
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"ZfrRestTest\\": "tests/"
51+
}
5352
}
5453
}

config/module.config.php

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,65 @@
1616
* and is licensed under the MIT license.
1717
*/
1818

19+
use ZfrRest\Factory\HttpExceptionListenerFactory;
20+
use ZfrRest\Factory\HydrateObjectPluginFactory;
21+
use ZfrRest\Factory\ModuleOptionsFactory;
22+
use ZfrRest\Factory\ResourceRendererFactory;
23+
use ZfrRest\Factory\ResourceStrategyFactory;
24+
use ZfrRest\Factory\ValidateIncomingDataPluginFactory;
25+
use ZfrRest\Mvc\Controller\Plugin\HydrateObject;
26+
use ZfrRest\Mvc\Controller\Plugin\ValidateIncomingData;
27+
use ZfrRest\Mvc\HttpExceptionListener;
28+
use ZfrRest\Mvc\ResourceResponseListener;
29+
use ZfrRest\Options\ModuleOptions;
30+
use ZfrRest\View\Helper\RenderPaginator;
31+
use ZfrRest\View\Helper\RenderResource;
32+
use ZfrRest\View\Renderer\ResourceRenderer;
33+
use ZfrRest\View\Strategy\ResourceStrategy;
34+
1935
return [
2036
'service_manager' => [
21-
'factories' => [
22-
/* Factories that do not map to a class */
23-
'ZfrRest\Cache' => 'ZfrRest\Factory\CacheFactory',
24-
'ZfrRest\View\Renderer\ResourceRenderer' => 'ZfrRest\Factory\DefaultResourceRendererFactory',
25-
26-
/* Factories that map to a class */
27-
'ZfrRest\Mvc\HttpExceptionListener' => 'ZfrRest\Factory\HttpExceptionListenerFactory',
28-
'ZfrRest\Mvc\Controller\MethodHandler\MethodHandlerPluginManager' => 'ZfrRest\Factory\MethodHandlerPluginManagerFactory',
29-
'ZfrRest\Options\ModuleOptions' => 'ZfrRest\Factory\ModuleOptionsFactory',
30-
'ZfrRest\Resource\Metadata\ResourceMetadataFactory' => 'ZfrRest\Factory\ResourceMetadataFactoryFactory',
31-
'ZfrRest\Resource\ResourcePluginManager' => 'ZfrRest\Factory\ResourcePluginManagerFactory',
32-
'ZfrRest\Router\Http\Matcher\AssociationSubPathMatcher' => 'ZfrRest\Factory\AssociationSubPathMatcherFactory',
33-
'ZfrRest\Router\Http\Matcher\BaseSubPathMatcher' => 'ZfrRest\Factory\BaseSubPathMatcherFactory',
34-
'ZfrRest\View\Strategy\ResourceStrategy' => 'ZfrRest\Factory\ResourceStrategyFactory'
37+
'invokables' => [
38+
ResourceResponseListener::class => ResourceResponseListener::class
3539
],
3640

37-
'invokables' => [
38-
'ZfrRest\Mvc\HttpMethodOverrideListener' => 'ZfrRest\Mvc\HttpMethodOverrideListener',
39-
'ZfrRest\Router\Http\Matcher\CollectionSubPathMatcher' => 'ZfrRest\Router\Http\Matcher\CollectionSubPathMatcher'
41+
'factories' => [
42+
HttpExceptionListener::class => HttpExceptionListenerFactory::class,
43+
ModuleOptions::class => ModuleOptionsFactory::class,
44+
ResourceRenderer::class => ResourceRendererFactory::class,
45+
ResourceStrategy::class => ResourceStrategyFactory::class
4046
]
4147
],
4248

43-
'route_manager' => [
49+
'controller_plugins' => [
4450
'factories' => [
45-
'ZfrRest\Router\Http\ResourceGraphRoute' => 'ZfrRest\Factory\ResourceGraphRouteFactory'
51+
ValidateIncomingData::class => ValidateIncomingDataPluginFactory::class,
52+
HydrateObject::class => HydrateObjectPluginFactory::class
4653
],
4754

4855
'aliases' => [
49-
'resourceGraphRoute' => 'ZfrRest\Router\Http\ResourceGraphRoute'
50-
],
56+
'validateIncomingData' => ValidateIncomingData::class,
57+
'hydrateObject' => HydrateObject::class
58+
]
5159
],
5260

53-
'controller_plugins' => [
61+
'view_helpers' => [
5462
'invokables' => [
55-
'paginatorWrapper' => 'ZfrRest\Mvc\Controller\Plugin\PaginatorWrapper',
56-
'resourceModel' => 'ZfrRest\Mvc\Controller\Plugin\ResourceModel'
63+
RenderPaginator::class => RenderPaginator::class,
64+
RenderResource::class => RenderResource::class
65+
],
66+
67+
'aliases' => [
68+
'renderPaginator' => RenderPaginator::class,
69+
'renderResource' => RenderResource::class
5770
]
5871
],
5972

6073
'view_manager' => [
6174
'strategies' => [
62-
'ZfrRest\View\Strategy\ResourceStrategy',
63-
'ViewJsonStrategy'
75+
ResourceStrategy::class
6476
]
6577
],
6678

67-
'zfr_rest' => [
68-
// Plugin managers configurations
69-
'method_handlers' => []
70-
]
79+
'zfr_rest' => []
7180
];

config/zfr_rest.global.php.dist

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@
77

88
return [
99
'zfr_rest' => [
10-
/**
11-
* Service name of the object manager instance. It is retrieved from the service manager. For instance, if you
12-
* are using Doctrine ORM Module, this value may be "doctrine.entitymanager.orm_default"
13-
*/
14-
// 'object_manager' => 'doctrine.entitymanager.orm_default',
15-
16-
/**
17-
* Specify the resource metadata drivers. This is used by ZfrRest to extract your mapping. Currently one
18-
* method is supported: annotations.
19-
*
20-
* To add an annotation driver:
21-
*
22-
* 'drivers' => [
23-
* [
24-
* 'class' => 'ZfrRest\Resource\Metadata\Driver\AnnotationDriver'
25-
* ]
26-
* ]
27-
*/
28-
// 'drivers' => [],
29-
30-
/**
31-
* Either a service name that returns a Zend\Cache\StorageInterface OR Doctrine\Common\Cache\Cache OR
32-
* a Zend\Cache\StorageInterface compliant config.
33-
*/
34-
// 'cache' => ['adapter' => 'apc'],
35-
3610
/**
3711
* Allow to map a custom exception to a HTTP exception. For instance:
3812
*
@@ -47,23 +21,11 @@ return [
4721
* a header "X-HTTP-Method-Override". This header allows to change the HTTP verb. This is useful in
4822
* some contexts (for instance, some companies' proxies only allow GET and POST methods)
4923
*/
50-
// 'register_http_method_override_listener' => false,
51-
52-
/**
53-
* If enabled, it allows the REST router to filter a collection list by identifiers. For instance, considering
54-
* a query /customers?$ids[]=1&$ids[]=2, it will be able to return a filtered collections
55-
*/
56-
// 'enable_coalesce_filtering' => false,
57-
58-
/**
59-
* The coalesce filtering query key
60-
*/
61-
// 'coalesce_filtering_query_key' => '$ids',
62-
63-
/**
64-
* Service manager configuration to configure the method handlers. A method handler handles a HTTP request
65-
* like GET, PUT...
66-
*/
67-
// 'method_handlers' => []
24+
// 'register_http_method_override_listener' => false
6825
]
6926
];
27+
28+
### Navigation
29+
30+
* Continue to [**Controllers**](/docs/02. Controllers.md)
31+
* Back to [the Index](/docs/README.md)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Installation and Configuration
2+
3+
Starting from ZfrRest 0.4.*, ZfrRest has very few options. Once you have retrieved it from Composer, all the
4+
available options can be configured by copying the `zfr_rest.global.php.dist` file into your `config/autoload` folder.
5+
6+
Here are the possible options:
7+
8+
* `exception_map`: allows to map an exception to a ZfrRest exception. It will automatically be catched by the listener
9+
and create an appropriate JSON response. You can learn more about error handling [in this section](/docs/01. Installation and configuration.md).
10+
* `register_http_method_override_listener`: in some companies, or if you are using standard HTML forms, you can be
11+
limited in the choice of HTTP verbs (most of the time, only POST and GET). By enabling this option, you can now send
12+
a header `X-HTTP-Method-Override` whose value is the HTTP method. ZfrRest will automatically replace the verb of the
13+
request.
14+
15+
* Continue to [**Controllers**](/docs/02. Controllers.md)
16+
* Back to [the Index](/docs/README.md)

docs/01. Introduction.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)