Commit 76776926 authored by Fabien Potencier's avatar Fabien Potencier

Revert "merged branch igorw/convert-only-existing-attribute (PR #769)"

This reverts commit e7d4a2fd, reversing
changes made to d6fe48ea.

Conflicts:
	doc/changelog.rst
	src/Silex/EventListener/ConverterListener.php
parent 03a326b3
......@@ -4,6 +4,7 @@ Changelog
1.2.0 (2013-XX-XX)
------------------
* Reverted "convert attributes on the request that actually exist"
* [BC BREAK] Routes are now always added in the order of their registration (even for mounted routes)
* Added run() on Route to be able to define the controller code
* Deprecated TwigCoreExtension (register the new HttpFragmentServiceProvider instead)
......
......@@ -50,10 +50,9 @@ class ConverterListener implements EventSubscriberInterface
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $converters = $route->getOption('_converters')) {
foreach ($converters as $name => $callback) {
if ($request->attributes->has($name)) {
$callback = $this->callbackResolver->isValid($callback) ? $this->callbackResolver->getCallback($callback) : $callback;
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
}
$callback = $this->callbackResolver->isValid($callback) ? $this->callbackResolver->getCallback($callback) : $callback;
$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