Commit f2fc754c authored by Igor Wiedler's avatar Igor Wiedler Committed by Fabien Potencier

Only convert attributes on the request that actually exist

parent d6fe48ea
......@@ -4,7 +4,7 @@ Changelog
1.1.1 (2013-XX-XX)
------------------
* n/a
* Only convert attributes on the request that actually exist.
1.1.0 (2013-07-04)
------------------
......
......@@ -46,7 +46,9 @@ class ConverterListener implements EventSubscriberInterface
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $converters = $route->getOption('_converters')) {
foreach ($converters as $name => $callback) {
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
if ($request->attributes->has($name)) {
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
}
}
}
}
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
/**
* Converter listener test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class ConverterTest extends \PHPUnit_Framework_TestCase
{
public function testConvertingNonExistentAttributeShouldNotCallConverter()
{
$called = false;
$converter = function () use (&$called) {
$called = true;
};
$app = new Application();
$app->get('/', function () { return 'hallo'; });
$app['controllers']->convert('foo', $converter);
$request = Request::create('/');
$app->handle($request);
$this->assertFalse($called);
}
}
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