Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
feature #7 Provides support for the PATCH method for HTTP (ramsey)
Browse files Browse the repository at this point in the history
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
fabpot committed Mar 14, 2014
2 parents 4039807 + 0f6956d commit 19265c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Silex/Application.php
Expand Up @@ -259,6 +259,19 @@ public function delete($pattern, $to = null)
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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Silex/ControllerCollection.php
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Silex/Tests/ApplicationTest.php
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Silex/Tests/RouterTest.php
Expand Up @@ -130,6 +130,10 @@ public function testMethodRouting()
return 'put resource';
});

$app->patch('/resource', function () {
return 'patch resource';
});

$app->delete('/resource', function () {
return 'delete resource';
});
Expand All @@ -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');
}

Expand Down

0 comments on commit 19265c0

Please sign in to comment.