Skip to content

Commit

Permalink
Provides support for the PATCH method for HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Jan 27, 2014
1 parent a793aa8 commit 0f6956d
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 0f6956d

Please sign in to comment.