Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 091a96c

Browse files
committed
Merge branch '2.3'
* 2.3: Fixing singular form for kisses, accesses and addresses. fixed some circular references [Security] fixed a leak in ExceptionListener [Security] fixed a leak in the ContextListener Ignore posix_istatty warnings removed unused variable [Form] fix iterator typehint typos Button missing getErrorsAsString() fixes #8084 Debug: Not calling undefined method anymore. If the form contained a submit button the call would fail and the debug of the form wasn't possible. Now it will work in all cases. This fixes #8084 Use isset() instead of array_key_exists() in DIC Fixed annotation [BrowserKit] fixed method/files/content when redirecting a request [BrowserKit] removed some headers when redirecting a request [BrowserKit] fixed headers when redirecting if history is set to false (refs #8697) [HttpKernel] fixed route parameters storage in the Request data collector (closes #8867) [BrowserKit] Pass headers when `followRedirect()` is called Return BC compatibility for `@Route` parameters and default values Conflicts: src/Symfony/Component/Security/Http/Firewall/ContextListener.php
2 parents 20fadcd + 702e652 commit 091a96c

File tree

18 files changed

+128
-36
lines changed

18 files changed

+128
-36
lines changed

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ public function enctype(FormView $view)
146146
*
147147
* Example usage:
148148
*
149-
* <?php echo view['form']->widget($form) ?>
149+
* <?php echo $view['form']->widget($form) ?>
150150
*
151151
* You can pass options during the call:
152152
*
153-
* <?php echo view['form']->widget($form, array('attr' => array('class' => 'foo'))) ?>
153+
* <?php echo $view['form']->widget($form, array('attr' => array('class' => 'foo'))) ?>
154154
*
155-
* <?php echo view['form']->widget($form, array('separator' => '+++++')) ?>
155+
* <?php echo $view['form']->widget($form, array('separator' => '+++++')) ?>
156156
*
157157
* @param FormView $view The view for which to render the widget
158158
* @param array $variables Additional variables passed to the template

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,24 @@ public function followRedirect()
492492
}
493493
}
494494

495+
$request = $this->internalRequest;
496+
497+
if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
498+
$method = 'get';
499+
$files = array();
500+
$content = null;
501+
} else {
502+
$method = $request->getMethod();
503+
$files = $request->getFiles();
504+
$content = $request->getContent();
505+
}
506+
507+
$server = $request->getServer();
508+
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);
509+
495510
$this->isMainRequest = false;
496511

497-
$response = $this->request('get', $this->redirect);
512+
$response = $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
498513

499514
$this->isMainRequest = true;
500515

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ public function testFollowRedirectWithMaxRedirects()
355355
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
356356
$client->request('GET', 'http://www.example.com/foo/foobar');
357357
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
358+
359+
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
360+
$client->request('POST', 'http://www.example.com/foo/foobar');
361+
362+
$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
358363
}
359364

360365
public function testFollowRedirectWithCookies()
@@ -371,6 +376,33 @@ public function testFollowRedirectWithCookies()
371376
$this->assertEquals(array('foo' => 'bar'), $client->getRequest()->getCookies());
372377
}
373378

379+
public function testFollowRedirectWithHeaders()
380+
{
381+
$headers = array(
382+
'HTTP_HOST' => 'www.example.com',
383+
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
384+
'CONTENT_TYPE' => 'application/vnd.custom+xml',
385+
'HTTPS' => false,
386+
);
387+
388+
$client = new TestClient();
389+
$client->followRedirects(false);
390+
$client->setNextResponse(new Response('', 302, array(
391+
'Location' => 'http://www.example.com/redirected',
392+
)));
393+
$client->request('GET', 'http://www.example.com/', array(), array(), array(
394+
'CONTENT_TYPE' => 'application/vnd.custom+xml',
395+
));
396+
397+
$this->assertEquals($headers, $client->getRequest()->getServer());
398+
399+
$client->followRedirect();
400+
401+
$headers['HTTP_REFERER'] = 'http://www.example.com/';
402+
403+
$this->assertEquals($headers, $client->getRequest()->getServer());
404+
}
405+
374406
public function testBack()
375407
{
376408
$client = new TestClient();

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
838838
$input->setInteractive(false);
839839
} elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) {
840840
$inputStream = $this->getHelperSet()->get('dialog')->getInputStream();
841-
if (!posix_isatty($inputStream)) {
841+
if (!@posix_isatty($inputStream)) {
842842
$input->setInteractive(false);
843843
}
844844
}

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ public function has($id)
240240
{
241241
$id = strtolower($id);
242242

243-
return array_key_exists($id, $this->services)
244-
|| array_key_exists($id, $this->aliases)
243+
return isset($this->services[$id])
244+
|| array_key_exists($id, $this->services)
245+
|| isset($this->aliases[$id])
245246
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
246247
;
247248
}
@@ -267,16 +268,21 @@ public function has($id)
267268
*/
268269
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
269270
{
270-
$id = strtolower($id);
271-
272-
// resolve aliases
273-
if (isset($this->aliases[$id])) {
274-
$id = $this->aliases[$id];
275-
}
276-
277-
// re-use shared service instance if it exists
278-
if (array_key_exists($id, $this->services)) {
279-
return $this->services[$id];
271+
// Attempt to retrieve the service by checking first aliases then
272+
// available services. Service IDs are case insensitive, however since
273+
// this method can be called thousands of times during a request, avoid
274+
// calling strotolower() unless necessary.
275+
foreach (array(false, true) as $strtolower) {
276+
if ($strtolower) {
277+
$id = strtolower($id);
278+
}
279+
if (isset($this->aliases[$id])) {
280+
$id = $this->aliases[$id];
281+
}
282+
// Re-use shared service instance if it exists.
283+
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
284+
return $this->services[$id];
285+
}
280286
}
281287

282288
if (isset($this->loading[$id])) {
@@ -339,7 +345,8 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
339345
*/
340346
public function initialized($id)
341347
{
342-
return array_key_exists(strtolower($id), $this->services);
348+
$id = strtolower($id);
349+
return isset($this->services[$id]) || array_key_exists($id, $this->services);
343350
}
344351

345352
/**

src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @author Bernhard Schussek <[email protected]>
2222
*
2323
* @deprecated Deprecated since version 2.3, to be removed in 3.0. Pass the
24-
* Request instance to {@link Form::process()} instead.
24+
* Request instance to {@link Form::handleRequest()} instead.
2525
*/
2626
class BindRequestListener implements EventSubscriberInterface
2727
{

src/Symfony/Component/Form/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ public function getErrorsAsString($level = 0)
751751

752752
foreach ($this->children as $key => $child) {
753753
$errors .= str_repeat(' ', $level).$key.":\n";
754-
if ($err = $child->getErrorsAsString($level + 4)) {
754+
if ($child instanceof self && $err = $child->getErrorsAsString($level + 4)) {
755755
$errors .= $err;
756756
} else {
757757
$errors .= str_repeat(' ', $level + 4)."No errors\n";
@@ -938,7 +938,7 @@ public function offsetUnset($name)
938938
/**
939939
* Returns the iterator for this group.
940940
*
941-
* @return \Iterator
941+
* @return \Traversable
942942
*/
943943
public function getIterator()
944944
{

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,20 @@ public function testPassZeroLabelToView()
571571
$this->assertSame('0', $view->vars['label']);
572572
}
573573

574+
public function testCanGetErrorsWhenButtonInForm()
575+
{
576+
$builder = $this->factory->createBuilder('form', null, array(
577+
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
578+
'required' => false,
579+
));
580+
$builder->add('foo', 'text');
581+
$builder->add('submit', 'submit');
582+
$form = $builder->getForm();
583+
584+
//This method should not throw a Fatal Error Exception.
585+
$form->getErrorsAsString();
586+
}
587+
574588
protected function getTestedType()
575589
{
576590
return 'form';

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public function collect(Request $request, Response $response, \Exception $except
5151
$attributes = array();
5252
foreach ($request->attributes->all() as $key => $value) {
5353
if ('_route' == $key && is_object($value)) {
54-
$value = $value->getPath();
54+
$attributes['_route'] = $this->varToString($value->getPath());
55+
} elseif ('_route_params' == $key) {
56+
foreach ($value as $key => $v) {
57+
$attributes['_route_params'][$key] = $this->varToString($v);
58+
}
59+
} else {
60+
$attributes[$key] = $this->varToString($value);
5561
}
56-
57-
$attributes[$key] = $this->varToString($value);
5862
}
5963

6064
$content = null;

src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function collect(Request $request, Response $response, \Exception $except
5050
$this->data['route'] = $this->guessRoute($request, $this->controllers[$request]);
5151
}
5252
}
53+
54+
unset($this->controllers[$request]);
5355
}
5456

5557
protected function guessRoute(Request $request, $controller)

src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public function onKernelResponse(FilterResponseEvent $event)
134134

135135
if ($master) {
136136
$this->saveProfiles($profile);
137+
138+
unset($this->children);
137139
}
138140
}
139141

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface
5959
protected $name;
6060
protected $startTime;
6161
protected $loadClassCache;
62-
protected $errorReportingLevel;
6362

6463
const VERSION = '2.4.0-DEV';
6564
const VERSION_ID = '20400';

src/Symfony/Component/PropertyAccess/StringUtil.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ class StringUtil
6363
// babies (baby)
6464
array('sei', 3, false, true, 'y'),
6565

66+
// accesses (access), addresses (address), kisses (kiss)
67+
array('sess', 4, true, false, 'ss'),
68+
6669
// analyses (analysis), ellipses (ellipsis), funguses (fungus),
6770
// neuroses (neurosis), theses (thesis), emphases (emphasis),
6871
// oases (oasis), crises (crisis), houses (house), bases (base),
69-
// atlases (atlas), kisses (kiss)
72+
// atlases (atlas)
7073
array('ses', 3, true, true, array('s', 'se', 'sis')),
7174

7275
// objectives (objective), alternative (alternatives)

src/Symfony/Component/PropertyAccess/Tests/StringUtilTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public function singularifyProvider()
7575
array('heroes', array('hero', 'heroe')),
7676
array('hoaxes', 'hoax'),
7777
array('irises', array('iris', 'irise', 'irisis')),
78-
array('kisses', array('kiss', 'kisse', 'kissis')),
78+
array('kisses', 'kiss'),
79+
array('addresses', 'address'),
80+
array('accesses', 'access'),
7981
array('knives', 'knife'),
8082
array('lives', 'life'),
8183
array('lice', 'louse'),

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
180180

181181
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
182182
foreach ($method->getParameters() as $param) {
183-
if ($param->isOptional()) {
183+
if (!isset($defaults[$param->getName()]) && $param->isOptional()) {
184184
$defaults[$param->getName()] = $param->getDefaultValue();
185185
}
186186
}

src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Routing\Tests\Loader;
1313

14+
use Symfony\Component\Routing\Annotation\Route;
15+
1416
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
1517
{
1618
protected $loader;
@@ -71,13 +73,18 @@ public function getLoadTests()
7173
return array(
7274
array(
7375
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
74-
array('name'=>'route1'),
75-
array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
76+
array('name' => 'route1'),
77+
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3')
7678
),
7779
array(
7880
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
79-
array('name'=>'route1', 'defaults' => array('arg2' => 'foo')),
80-
array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
81+
array('name' => 'route1', 'defaults' => array('arg2' => 'foo')),
82+
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3')
83+
),
84+
array(
85+
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
86+
array('name' => 'route1', 'defaults' => array('arg2' => 'foobar')),
87+
array('arg2' => false, 'arg3' => 'defaultValue3')
8188
),
8289
);
8390
}
@@ -108,12 +115,11 @@ public function testLoad($className, $routeDatas = array(), $methodArgs = array(
108115
$this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
109116
$this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
110117
$this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
111-
$this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation');
118+
$this->assertSame(array_replace($methodArgs, $routeDatas['defaults']), $route->getDefaults(), '->load preserves defaults annotation');
112119
}
113120

114121
private function getAnnotatedRoute($datas)
115122
{
116-
return new \Symfony\Component\Routing\Annotation\Route($datas);
123+
return new Route($datas);
117124
}
118-
119125
}

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ContextListener implements ListenerInterface
3737
private $logger;
3838
private $userProviders;
3939
private $dispatcher;
40+
private $registered;
4041

4142
public function __construct(SecurityContextInterface $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
4243
{
@@ -64,8 +65,9 @@ public function __construct(SecurityContextInterface $context, array $userProvid
6465
*/
6566
public function handle(GetResponseEvent $event)
6667
{
67-
if (null !== $this->dispatcher && $event->isMasterRequest()) {
68+
if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
6869
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
70+
$this->registered = true;
6971
}
7072

7173
$request = $event->getRequest();

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public function register(EventDispatcherInterface $dispatcher)
7676
*/
7777
public function onKernelException(GetResponseForExceptionEvent $event)
7878
{
79+
// we need to remove ourselves as the exception listener can be
80+
// different depending on the Request
81+
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
82+
7983
$exception = $event->getException();
8084
$request = $event->getRequest();
8185

0 commit comments

Comments
 (0)