Commit 0f6956d1 authored by Ben Ramsey's avatar Ben Ramsey

Provides support for the PATCH method for HTTP

http://tools.ietf.org/html/rfc5789
parent a793aa89
......@@ -259,6 +259,19 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return $this['controllers']->delete($pattern, $to);
}
/**
* Maps a PATCH request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function patch($pattern, $to = null)
{
return $this['controllers']->patch($pattern, $to);
}
/**
* Adds an event listener that listens on the specified events.
*
......
......@@ -127,6 +127,19 @@ class ControllerCollection
return $this->match($pattern, $to)->method('DELETE');
}
/**
* Maps a PATCH request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function patch($pattern, $to = null)
{
return $this->match($pattern, $to)->method('PATCH');
}
public function __call($method, $arguments)
{
if (!method_exists($this->defaultRoute, $method)) {
......
......@@ -46,6 +46,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$returnValue = $app->put('/foo', function () {});
$this->assertInstanceOf('Silex\Controller', $returnValue);
$returnValue = $app->patch('/foo', function () {});
$this->assertInstanceOf('Silex\Controller', $returnValue);
$returnValue = $app->delete('/foo', function () {});
$this->assertInstanceOf('Silex\Controller', $returnValue);
}
......
......@@ -130,6 +130,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase
return 'put resource';
});
$app->patch('/resource', function () {
return 'patch resource';
});
$app->delete('/resource', function () {
return 'delete resource';
});
......@@ -140,6 +144,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
$this->checkRouteResponse($app, '/resource', 'get resource');
$this->checkRouteResponse($app, '/resource', 'post resource', 'post');
$this->checkRouteResponse($app, '/resource', 'put resource', 'put');
$this->checkRouteResponse($app, '/resource', 'patch resource', 'patch');
$this->checkRouteResponse($app, '/resource', 'delete resource', 'delete');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment