Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'promote/develop'
Browse files Browse the repository at this point in the history
Promote develop to master in preparation for 1.1.
  • Loading branch information
weierophinney committed Apr 16, 2015
2 parents 426e9a4 + 41c9a4e commit 6de6c06
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 39 deletions.
37 changes: 18 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,34 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.0-dev",
"dev-develop": "1.1-dev"
"dev-master": "1.1-dev",
"dev-develop": "1.2-dev"
}
},
"require": {
"php": ">=5.3.23",
"zendframework/zend-eventmanager": "~2.3",
"zendframework/zend-json": "~2.3",
"zendframework/zend-loader": "~2.3",
"zendframework/zend-mvc": "~2.3.0",
"zendframework/zend-paginator": "~2.3",
"zendframework/zend-stdlib": "~2.3",
"zendframework/zend-eventmanager": "~2.4",
"zendframework/zend-json": "~2.4",
"zendframework/zend-loader": "~2.4",
"zendframework/zend-mvc": "~2.4",
"zendframework/zend-paginator": "~2.4",
"zendframework/zend-stdlib": "~2.4",
"zfcampus/zf-api-problem": "~1.0",
"zfcampus/zf-content-negotiation": "~1.0",
"zfcampus/zf-hal": ">=1.0.2,<2.0.0",
"zfcampus/zf-mvc-auth": "~1.0",
"zfcampus/zf-oauth2": "~1.0"
"zfcampus/zf-hal": "~1.1",
"zfcampus/zf-mvc-auth": "~1.1"
},
"require-dev": {
"phpunit/PHPUnit": "3.7.*",
"squizlabs/php_codesniffer": "~2.0",
"zendframework/zend-console": "~2.3",
"zendframework/zend-escaper": "~2.3",
"zendframework/zend-http": "~2.3",
"zendframework/zend-inputfilter": "~2.3",
"zendframework/zend-servicemanager": "~2.3",
"zendframework/zend-uri": "~2.3",
"zendframework/zend-validator": "~2.3",
"zendframework/zend-view": "~2.3"
"zendframework/zend-console": "~2.4",
"zendframework/zend-escaper": "~2.4",
"zendframework/zend-http": "~2.4",
"zendframework/zend-inputfilter": "~2.4",
"zendframework/zend-servicemanager": "~2.4",
"zendframework/zend-uri": "~2.4",
"zendframework/zend-validator": "~2.4",
"zendframework/zend-view": "~2.4"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 20 additions & 2 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Traversable;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
use Zend\Http\Response;
use Zend\InputFilter\InputFilterInterface;
use Zend\Mvc\Router\RouteMatch;
use Zend\Stdlib\Parameters;
Expand Down Expand Up @@ -240,6 +241,7 @@ public function create($data)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down Expand Up @@ -283,6 +285,7 @@ public function update($id, $data)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down Expand Up @@ -335,6 +338,7 @@ public function replaceList($data)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down Expand Up @@ -379,6 +383,7 @@ public function patch($id, $data)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down Expand Up @@ -436,6 +441,7 @@ public function patchList($data)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand All @@ -462,10 +468,15 @@ public function delete($id)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
if (!is_bool($last) && (!$last instanceof ApiProblem) && (!$last instanceof ApiProblemResponse)) {
if (!is_bool($last)
&& ! $last instanceof ApiProblem
&& ! $last instanceof ApiProblemResponse
&& ! $last instanceof Response
) {
return false;
}
return $last;
Expand Down Expand Up @@ -493,10 +504,15 @@ public function deleteList($data = null)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
if (!is_bool($last) && (!$last instanceof ApiProblem) && (!$last instanceof ApiProblemResponse)) {
if (! is_bool($last)
&& ! $last instanceof ApiProblem
&& ! $last instanceof ApiProblemResponse
&& ! $last instanceof Response
) {
return false;
}
return $last;
Expand All @@ -520,6 +536,7 @@ public function fetch($id)
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down Expand Up @@ -550,6 +567,7 @@ public function fetchAll()
$results = $events->trigger($event, function ($result) {
return ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
);
});
$last = $results->last();
Expand Down
36 changes: 22 additions & 14 deletions src/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ public function setRoute($route)
*/
public function onDispatch(MvcEvent $e)
{
if (!$this->getResource()) {
if (! $this->getResource()) {
throw new DomainException(sprintf(
'%s requires that a %s\ResourceInterface object is composed; none provided',
__CLASS__,
__NAMESPACE__
));
}

if (!$this->route) {
if (! $this->route) {
throw new DomainException(sprintf(
'%s requires that a route name for the resource is composed; none provided',
__CLASS__
Expand All @@ -327,20 +327,14 @@ public function onDispatch(MvcEvent $e)
// Check for an API-Problem in the event
$return = $e->getParam('api-problem', false);

// Override RESTful deleteList method
if (strtolower($e->getRequest()->getMethod()) == 'delete' &&
$this->getIdentifier($e->getRouteMatch(), $e->getRequest()) === false) {
$return = $this->deleteList($this->processBodyContent($e->getRequest()));
}

// If no return value dispatch the parent event
if (!$return) {
if (! $return) {
$return = parent::onDispatch($e);
}

if (!$return instanceof ApiProblem
&& !$return instanceof HalEntity
&& !$return instanceof HalCollection
if (! $return instanceof ApiProblem
&& ! $return instanceof HalEntity
&& ! $return instanceof HalCollection
) {
return $return;
}
Expand All @@ -354,7 +348,6 @@ public function onDispatch(MvcEvent $e)

// Use content negotiation for creating the view model
$viewModel = new ContentNegotiationViewModel(array('payload' => $return));
$viewModel->setTerminal(true);
$e->setResult($viewModel);

return $viewModel;
Expand All @@ -380,6 +373,7 @@ public function create($data)

if ($entity instanceof ApiProblem
|| $entity instanceof ApiProblemResponse
|| $entity instanceof Response
) {
return $entity;
}
Expand Down Expand Up @@ -426,6 +420,7 @@ public function delete($id)

if ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
) {
return $result;
}
Expand All @@ -438,7 +433,13 @@ public function delete($id)
return $response;
}

public function deleteList($data = null)
/**
* Delete a collection of entities as specified.
*
* @param mixed $data Typically an array
* @return Response|ApiProblem
*/
public function deleteList($data)
{
$events = $this->getEventManager();
$events->trigger('deleteList.pre', $this, array());
Expand All @@ -453,6 +454,7 @@ public function deleteList($data = null)

if ($result instanceof ApiProblem
|| $result instanceof ApiProblemResponse
|| $result instanceof Response
) {
return $result;
}
Expand Down Expand Up @@ -487,6 +489,7 @@ public function get($id)

if ($entity instanceof ApiProblem
|| $entity instanceof ApiProblemResponse
|| $entity instanceof Response
) {
return $entity;
}
Expand Down Expand Up @@ -524,6 +527,7 @@ public function getList()

if ($collection instanceof ApiProblem
|| $collection instanceof ApiProblemResponse
|| $collection instanceof Response
) {
return $collection;
}
Expand Down Expand Up @@ -638,6 +642,7 @@ public function patch($id, $data)

if ($entity instanceof ApiProblem
|| $entity instanceof ApiProblemResponse
|| $entity instanceof Response
) {
return $entity;
}
Expand Down Expand Up @@ -679,6 +684,7 @@ public function update($id, $data)

if ($entity instanceof ApiProblem
|| $entity instanceof ApiProblemResponse
|| $entity instanceof Response
) {
return $entity;
}
Expand Down Expand Up @@ -715,6 +721,7 @@ public function patchList($data)

if ($collection instanceof ApiProblem
|| $collection instanceof ApiProblemResponse
|| $collection instanceof Response
) {
return $collection;
}
Expand Down Expand Up @@ -751,6 +758,7 @@ public function replaceList($data)

if ($collection instanceof ApiProblem
|| $collection instanceof ApiProblemResponse
|| $collection instanceof Response
) {
return $collection;
}
Expand Down
34 changes: 34 additions & 0 deletions test/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPUnit_Framework_TestCase as TestCase;
use stdClass;
use Zend\EventManager\EventManager;
use Zend\Http\Response;
use Zend\Mvc\Router\RouteMatch;
use Zend\Stdlib\ArrayObject;
use Zend\Stdlib\Parameters;
Expand Down Expand Up @@ -518,4 +519,37 @@ public function testFetchAllShouldAllowReturningArbitraryObjects()
$test = $this->resource->fetchAll();
$this->assertSame($return, $test);
}

public function actions()
{
return array(
'get-list' => array('fetchAll', array(null)),
'get' => array('fetch', array(1)),
'post' => array('create', array(array())),
'put-list' => array('replaceList', array(array())),
'put' => array('update', array(1, array())),
'patch-list' => array('patchList', array(array())),
'patch' => array('patch', array(1, array())),
'delete-list' => array('deleteList', array(array())),
'delete' => array('delete', array(1)),
);
}

/**
* @group 68
* @dataProvider actions
*/
public function testAllowsReturningResponsesReturnedFromResources($action, $argv)
{
$response = new Response();
$response->setStatusCode(418);

$events = $this->resource->getEventManager();
$events->attach($action, function ($e) use ($response) {
return $response;
});

$result = call_user_func_array(array($this->resource, $action), $argv);
$this->assertSame($response, $result);
}
}
Loading

0 comments on commit 6de6c06

Please sign in to comment.