Commit 6f9cca8b authored by Fabien Potencier's avatar Fabien Potencier

merged branch marijn/feature/constructor-parameters (PR #556)

This PR was merged into the master branch.

Commits
-------

6543379c Allow constructor arguments.

Discussion
----------

Allow constructor arguments.

Unfortunately my phpunit installation is horribly broken so I can't run the tests right now...

---------------------------------------------------------------------------

by igorw at 2012-11-27T00:21:38Z

👍

---------------------------------------------------------------------------

by igorw at 2012-11-27T00:21:49Z

Docs?

---------------------------------------------------------------------------

by igorw at 2012-11-27T00:24:24Z

The parent constructor should probably be called at the end, that allows parameters to override the default services. And you should add a test case for that too.

---------------------------------------------------------------------------

by GromNaN at 2012-11-27T07:54:31Z

@igorw The parent constructor replaces everything, so it cannot be called at the end.
https://github.com/fabpot/Pimple/blob/master/lib/Pimple.php#L46

---------------------------------------------------------------------------

by fabpot at 2013-01-03T08:10:28Z

What about just calling `array_replace($this->values, $values)` at the end of the constructor instead?

---------------------------------------------------------------------------

by igorw at 2013-01-03T08:35:02Z

Sounds good to me.
parents ed53b169 6543379c
...@@ -52,10 +52,16 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -52,10 +52,16 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
private $booted = false; private $booted = false;
/** /**
* Constructor. * Instantiate a new Application.
*
* Objects and parameters can be passed as argument to the constructor.
*
* @param array $values The parameters or objects.
*/ */
public function __construct() public function __construct(array $values = array())
{ {
parent::__construct($values);
$app = $this; $app = $this;
$this['logger'] = null; $this['logger'] = null;
......
...@@ -48,6 +48,14 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -48,6 +48,14 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('Silex\Controller', $returnValue); $this->assertInstanceOf('Silex\Controller', $returnValue);
} }
public function testConstructorInjection ()
{
$params = array("param" => "value");
$app = new Application($params);
$this->assertSame($params['param'], $app['param']);
}
public function testGetRequest() public function testGetRequest()
{ {
$request = Request::create('/'); $request = Request::create('/');
......
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