Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

feature #7 Provides support for the PATCH method for HTTP (ramsey)

This PR was merged into the 1.2.x-dev branch.

Discussion
----------

Provides support for the PATCH method for HTTP

This pull request allows Silex routes to be specified to handle the `PATCH` method for HTTP. Without this, when trying to specify that a route accepts `PATCH` requests, Silex throws a `BadMethodCallException` with the message `Method "Silex\Route::patch" does not exist.`

#### References:

* [PATCH Method for HTTP](http://tools.ietf.org/html/rfc5789)

Commits
-------

0f6956d Provides support for the PATCH method for HTTP
  • Loading branch information...
commit 19265c0c51e5c1aaaf729275d8a1b3583cb40d23 2 parents 4039807 + 0f6956d
@fabpot fabpot authored
View
13 src/Silex/Application.php
@@ -260,6 +260,19 @@ public function delete($pattern, $to = null)
}
/**
+ * 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.
*
* @param string $eventName The event to listen on
View
13 src/Silex/ControllerCollection.php
@@ -139,6 +139,19 @@ public function delete($pattern, $to = null)
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)) {
View
3  tests/Silex/Tests/ApplicationTest.php
@@ -46,6 +46,9 @@ public function testMatchReturnValue()
$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);
}
View
5 tests/Silex/Tests/RouterTest.php
@@ -130,6 +130,10 @@ public function testMethodRouting()
return 'put resource';
});
+ $app->patch('/resource', function () {
+ return 'patch resource';
+ });
+
$app->delete('/resource', function () {
return 'delete resource';
});
@@ -140,6 +144,7 @@ public function testMethodRouting()
$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');
}
Please sign in to comment.
Something went wrong with that request. Please try again.