8000 Merge branch '2.3' into 2.4 · src-run/symfony@43b83cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 43b83cf

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: remove obsolete test file [FrameworkBundle] output failed matched path for clarification bug symfony#10242 Missing checkPreAuth from RememberMeAuthenticationProvider [Validator] Fixed StaticMethodLoaderTest to actually test something [Form] Fixed ValidatorTypeGuesser to guess properties without constraints not to be required Use request format from request in twig ExceptionController [Form] Moved POST_MAX_SIZE validation from FormValidator to request handler [Form] Add a form error if post_max_size has been reached. Response::isNotModified returns true when If-Modified-Since is later than Last-Modified [WebProfilerBundle] turbolinks compatibility Conflicts: src/Symfony/Component/Form/CHANGELOG.md src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
2 parents 9333395 + d671406 commit 43b83cf

File tree

26 files changed

+414
-283
lines changed

26 files changed

+414
-283
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8989
}
9090

9191
if (!$matches) {
92-
$output->writeln('<fg=red>None of the routes match</>');
92+
$output->writeln(sprintf('<fg=red>None of the routes match the path "%s"</>', $input->getArgument('path_info')));
9393

9494
return 1;
9595
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@
147147
</service>
148148

149149
<!-- FormTypeHttpFoundationExtension -->
150+
<service id="form.server_params" class="Symfony\Component\Form\Util\ServerParams" public="false"/>
151+
150152
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
151153
<tag name="form.type_extension" alias="form" />
154+
<argument type="service" id="form.server_params"/>
152155
</service>
153156

154157
<!-- FormTypeValidatorExtension -->

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TestCaseMethod.tpl

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ public function __construct(\Twig_Environment $twig, $debug)
3939
* @param Request $request The request
4040
* @param FlattenException $exception A FlattenException instance
4141
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
42-
* @param string $_format The format to use for rendering (html, xml, ...)
4342
*
4443
* @return Response
4544
*
4645
* @throws \InvalidArgumentException When the exception template does not exist
4746
*/
48-
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
47+
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
4948
{
5049
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
5150

5251
$code = $exception->getStatusCode();
5352

5453
return new Response($this->twig->render(
55-
$this->findTemplate($request, $_format, $code, $this->debug),
54+
$this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
5655
array(
5756
'status_code' => $code,
5857
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- START of Symfony2 Web Debug Toolbar -->
22
{% if 'normal' != position %}
3-
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar">
3+
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
44
<a href="javascript:void(0);" title="Show Symfony toolbar" onclick="
55
var elem = this.parentNode;
66
if (elem.style.display == 'none') {
@@ -24,7 +24,7 @@
2424
<div id="sfToolbarClearer-{{ token }}" style="clear: both; height: 38px;"></div>
2525
{% endif %}
2626

27-
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset">
27+
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset" data-no-turbolink>
2828
{% for name, template in templates %}
2929
{{ template.renderblock('toolbar', {
3030
'collector': profile.getcollector(name),

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5656
->setDataLocked($isDataOptionSet)
5757
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
5858
->setMethod($options['method'])
59-
->setAction($options['action'])
60-
;
59+
->setAction($options['action']);
6160

6261
if ($options['trim']) {
6362
$builder->addEventSubscriber(new TrimListener());
@@ -171,25 +170,26 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
171170
));
172171

173172
$resolver->setDefaults(array(
174-
'data_class' => $dataClass,
175-
'empty_data' => $emptyData,
176-
'trim' => true,
177-
'required' => true,
178-
'read_only' => false,
179-
'max_length' => null,
180-
'pattern' => null,
181-
'property_path' => null,
182-
'mapped' => true,
183-
'by_reference' => true,
184-
'error_bubbling' => $errorBubbling,
185-
'label_attr' => array(),
186-
'virtual' => null,
187-
'inherit_data' => $inheritData,
188-
'compound' => true,
189-
'method' => 'POST',
173+
'data_class' => $dataClass,
174+
'empty_data' => $emptyData,
175+
'trim' => true,
176+
'required' => true,
177+
'read_only' => false,
178+
'max_length' => null,
179+
'pattern' => null,
180+
'property_path' => null,
181+
'mapped' => true,
182+
'by_reference' => true,
183+
'error_bubbling' => $errorBubbling,
184+
'label_attr' => array(),
185+
'virtual' => null,
186+
'inherit_data' => $inheritData,
187+
'compound' => true,
188+
'method' => 'POST',
190189
// According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
191190
// section 4.2., empty URIs are considered same-document references
192-
'action' => '',
191+
'action' => '',
192+
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
193193
));
194194

195195
$resolver->setAllowedTypes(array(

src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationExtension.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\HttpFoundation;
1313

1414
use Symfony\Component\Form\AbstractExtension;
15+
use Symfony\Component\Form\Util\ServerParams;
1516

1617
/**
1718
* Integrates the HttpFoundation component with the Form library.
@@ -20,10 +21,20 @@
2021
*/
2122
class HttpFoundationExtension extends AbstractExtension
2223
{
24+
/**
25+
* @var ServerParams
26+
*/
27+
private $serverParams;
28+
29+
public function __construct(ServerParams $serverParams = null)
30+
{
31+
$this->serverParams = $serverParams;
32+
}
33+
2334
protected function loadTypeExtensions()
2435
{
2536
return array(
26-
new Type\FormTypeHttpFoundationExtension(),
37+
new Type\FormTypeHttpFoundationExtension($this->serverParams),
2738
);
2839
}
2940
}

src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Symfony\Component\Form\Extension\HttpFoundation;
1313

1414
use Symfony\Component\Form\Exception\UnexpectedTypeException;
15+
use Symfony\Component\Form\FormError;
1516
use Symfony\Component\Form\FormInterface;
1617
use Symfony\Component\Form\RequestHandlerInterface;
18+
use Symfony\Component\Form\Util\ServerParams;
1719
use Symfony\Component\HttpFoundation\Request;
1820

1921
/**
@@ -24,6 +26,19 @@
2426
*/
2527
class HttpFoundationRequestHandler implements RequestHandlerInterface
2628
{
29+
/**
30+
* @var ServerParams
31+
*/
32+
private $serverParams;
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function __construct(ServerParams $serverParams = null)
38+
{
39+
$this->serverParams = $serverParams ?: new ServerParams();
40+
}
41+
2742
/**
2843
* {@inheritdoc}
2944
*/
@@ -53,6 +68,25 @@ public function handleRequest(FormInterface $form, $request = null)
5368
$data = $request->query->get($name);
5469
}
5570
} else {
71+
// Mark the form with an error if the uploaded size was too large
72+
// This is done here and not in FormValidator because $_POST is
73+
// empty when that error occurs. Hence the form is never submitted.
74+
$contentLength = $this->serverParams->getContentLength();
75+
$maxContentLength = $this->serverParams->getPostMaxSize();
76+
77+
if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
78+
// Submit the form, but don't clear the default values
79+
$form->submit(null, false);
80+
81+
$form->addError(new FormError(
82+
$form->getConfig()->getOption('post_max_size_message'),
83+
null,
84+
array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())
85+
));
86+
87+
return;
88+
}
89+
5690
if ('' === $name) {
5791
$params = $request->request->all();
5892
$files = $request->files->all();

src/Symfony/Component/Form/Extension/HttpFoundation/Type/FormTypeHttpFoundationExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
1616
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
1717
use Symfony\Component\Form\FormBuilderInterface;
18+
use Symfony\Component\Form\Util\ServerParams;
1819

1920
/**
2021
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -31,10 +32,10 @@ class FormTypeHttpFoundationExtension extends AbstractTypeExtension
3132
*/
3233
private $requestHandler;
3334

34-
public function __construct()
35+
public function __construct(ServerParams $serverParams = null)
3536
{
3637
$this->listener = new BindRequestListener();
37-
$this->requestHandler = new HttpFoundationRequestHandler();
38+
$this->requestHandler = new HttpFoundationRequestHandler($serverParams);
3839
}
3940

4041
/**

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Form\Extension\Validator\Constraints;
1313

1414
use Symfony\Component\Form\FormInterface;
15-
use Symfony\Component\Form\Extension\Validator\Util\ServerParams;
1615
use Symfony\Component\Validator\Constraint;
1716
use Symfony\Component\Validator\ConstraintValidator;
1817

@@ -21,22 +20,6 @@
2120
*/
2221
class FormValidator extends ConstraintValidator
2322
{
24-
/**
25-
* @var ServerParams
26-
*/
27-
private $serverParams;
28-
29-
/**
30-
* Creates a validator with the given server parameters.
31-
*
32-
* @param ServerParams $params The server parameters. Default
33-
* parameters are created if null.
34-
*/
35-
public function __construct(ServerParams $params = null)
36-
{
37-
$this->serverParams = $params ?: new ServerParams();
38-
}
39-
4023
/**
4124
* {@inheritdoc}
4225
*/
@@ -113,21 +96,6 @@ public function validate($form, Constraint $constraint)
11396
$form->getExtraData()
11497
);
11598
}
116-
117-
// Mark the form with an error if the uploaded size was too large
118-
$length = $this->serverParams->getContentLength();
119-
120-
if ($form->isRoot() && null !== $length) {
121-
$max = $this->serverParams->getPostMaxSize();
122-
123-
if (!empty($max) && $length > $max) {
124-
$this->context->addViolation(
125-
$config->getOption('post_max_size_message'),
126-
array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()),
127-
$length
128-
);
129-
}
130-
}
13199
}
132100

133101
/**

src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
6666
'invalid_message' => 'This value is not valid.',
6767
'invalid_message_parameters' => array(),
6868
'extra_fields_message' => 'This form should not contain extra fields.',
69-
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
7069
));
7170

7271
$resolver->setNormalizers(array(

src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,6 @@
1414
/**
1515
* @author Bernhard Schussek <bschussek@gmail.com>
1616
*/
17-
class ServerParams
17+
class ServerParams extends \Symfony\Component\Form\Util\ServerParams
1818
{
19-
/**
20-
* Returns maximum post size in bytes.
21-
*
22-
* @return null|int The maximum post size in bytes
23-
*/
24-
public function getPostMaxSize()
25-
{
26-
$iniMax = strtolower($this->getNormalizedIniPostMaxSize());
27-
28-
if ('' === $iniMax) {
29-
return;
30-
}
31-
32-
$max = ltrim($iniMax, '+');
33-
if (0 === strpos($max, '0x')) {
34-
$max = intval($max, 16);
35-
} elseif (0 === strpos($max, '0')) {
36-
$max = intval($max, 8);
37-
} else {
38-
$max = intval($max);
39-
}
40-
41-
switch (substr($iniMax, -1)) {
42-
case 't': $max *= 1024;
43-
case 'g': $max *= 1024;
44-
case 'm': $max *= 1024;
45-
case 'k': $max *= 1024;
46-
}
47-
48-
return $max;
49-
}
50-
51-
/**
52-
* Returns the normalized "post_max_size" ini setting.
53-
*
54-
* @return string
55-
*/
56-
public function getNormalizedIniPostMaxSize()
57-
{
58-
return strtoupper(trim(ini_get('post_max_size')));
59-
}
60-
61-
/**
62-
* Returns the content length of the request.
63-
*
64-
* @return mixed The request content length.
65-
*/
66-
public function getContentLength()
67-
{
68-
return isset($_SERVER['CONTENT_LENGTH'])
69-
? (int) $_SERVER['CONTENT_LENGTH']
70-
: null;
71-
}
7219
}

0 commit comments

Comments
 (0)
0