zf-fr/zfr-rest — pull request #122 by bakura10 (2014-02-16 18:53:45+00:00)
Title: Simplfy controllers

ping @Ocramius @danizord @orkin

This PR tries to remove the overhead that was introduced in controllers with the fact that we forced user returning ResourceModel to trigger the automatic serialization. This is indeed a good idea and I want to keep that, however it forced user to complicate their controller, as shown below:

```php
public function get(User $user, ResourceMetadataInterface $resourceMetadata)
{
return new ResourceModel(new Resource($user, $resourceMetadata));
}
```

First, I removed the fact that handlers automatically add the metadata as a second parameter. It's useless 99% of the time, as the resource type usually stay the same, and instead I have added a getter in the controller to retrieve the matchedResource, so the metadata can still be retrieved this way:

```php
$resource = $this->getMatchedResource()->getMetadata();
```

Now, in controllers, the ResourceModel is created using a utility controller plugin, and the controller action can be rewritten as this:

```php
public function get(User $user)
{
return $this->resourceModel($user);
}
```

ResourceModel plugin will fetch the matched resource metadata.

If an action changes the type (for instance a get user from the UserController that would return another type of object), hence needing to change the resource metadata, the resource model supports an optional second parameter which is the ResourceMetadata.

With this PR, we keep the fact that a ResourceModel must be returned, but we keep the simpler usage we had before.