Commit 8a509371 authored by Fabien Potencier's avatar Fabien Potencier

feature #922 Various fixes (fabpot)

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

Discussion
----------

Various fixes

Some merged PRs from fabpot/Silex repo.

Commits
-------

72aae9e1 fixed CS
e4e0fef3 fixed wrong merge
33903336 minor #4 Changed fetchAssoc to fetchAll (gelbander)
c119f90e Merge remote-tracking branch 'WouterJ/doc_fixes'
19265c0c feature #7 Provides support for the PATCH method for HTTP (ramsey)
0f6956d1 Provides support for the PATCH method for HTTP
919c32c7 Some doc fixes
03839264 Changed fetchAssoc to fetchAll
parents 40398077 72aae9e1
......@@ -18,10 +18,12 @@ aims to be:
In a nutshell, you define controllers and map them to routes, all in one step.
**Let's go!**::
Usage
-----
// web/index.php
.. code-block:: php
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
......@@ -35,17 +37,23 @@ In a nutshell, you define controllers and map them to routes, all in one step.
All that is needed to get access to the Framework is to include the
autoloader.
Next we define a route to ``/hello/{name}`` that matches for ``GET`` requests.
Next a route for ``/hello/{name}`` that matches for ``GET`` requests is defined.
When the route matches, the function is executed and the return value is sent
back to the client.
Finally, the app is run. Visit ``/hello/world`` to see the result. It's really
that easy!
Installing Silex is as easy as it can get. `Download`_ the archive file,
extract it, and you're done!
Installation
------------
Installing Silex is as easy as it can get. The recommend method is using
Composer_ and requiring `silex/silex`_. Another way is to `download`_ the
archive file and extract it.
.. _Download: http://silex.sensiolabs.org/download
.. _Symfony2: http://symfony.com/
.. _Pimple: http://pimple.sensiolabs.org/
.. _Sinatra: http://www.sinatrarb.com/
.. _Composer: http://getcomposer.org/
.. _`download`: http://silex.sensiolabs.org/download
.. _`silex/silex`: https://packagist.org/packages/silex/silex
......@@ -123,9 +123,9 @@ The first registered connection is the default and can simply be accessed as
you would if there was only one connection. Given the above configuration,
these two lines are equivalent::
$app['db']->fetchAssoc('SELECT * FROM table');
$app['db']->fetchAll('SELECT * FROM table');
$app['dbs']['mysql_read']->fetchAssoc('SELECT * FROM table');
$app['dbs']['mysql_read']->fetchAll('SELECT * FROM table');
Using multiple connections::
......
This diff is collapsed.
......@@ -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.
*
......
......@@ -139,6 +139,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);
}
......@@ -146,7 +149,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$app = new Application();
$app['pass'] = false;
$app->on('test', function(Event $e) use ($app) {
$app->on('test', function (Event $e) use ($app) {
$app['pass'] = true;
});
......@@ -380,7 +383,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$app->get('/foo', function () use (&$containerTarget) {
$containerTarget[] = '1_routeTriggered';
return new StreamedResponse(function() use (&$containerTarget) {
return new StreamedResponse(function () use (&$containerTarget) {
$containerTarget[] = '3_responseSent';
});
});
......@@ -553,7 +556,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
ErrorHandler::register();
$app['monolog.logfile'] = 'php://memory';
$app->register(new MonologServiceProvider());
$app->get('/foo/', function() { return 'ok'; });
$app->get('/foo/', function () { return 'ok'; });
$response = $app->handle(Request::create('/foo'));
$this->assertEquals(301, $response->getStatusCode());
......
......@@ -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