10000 Merge branch '2.8' into 3.1 · symfony/symfony@27e2b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 27e2b9d

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: [ClassLoader] Use only forward slashes in generated class map ensure the proper context for nested validations bug #20653 [WebProfilerBundle] Profiler includes ghost panels
2 parents e4a2c17 + d3014e4 commit 27e2b9d

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
{% for name, template in templates %}
115115
{% set menu -%}
116116
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
117-
{{ block('menu', template) }}
117+
{{- block('menu', template) -}}
118118
{% endwith %}
119119
{%- endset %}
120120
{% if menu is not empty %}

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
6060
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
6161
}
6262
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
63-
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
63+
$cache = $cacheDir.'/'.$name.$extension;
6464

6565
// auto-reload
6666
$reload = false;
@@ -108,7 +108,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
108108
REGEX;
109109
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
110110

111-
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
111+
$cacheDir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $cacheDir));
112112
$files = array();
113113
$content = '';
114114
foreach (self::getOrderedClasses($classes) as $class) {
@@ -120,19 +120,19 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
120120
$c = file_get_contents($file);
121121

122122
if (preg_match($dontInlineRegex, $c)) {
123-
$file = explode(DIRECTORY_SEPARATOR, $file);
123+
$file = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $file));
124124

125125
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
126126
if ($file[$i] !== $cacheDir[$i]) {
127127
break;
128128
}
129129
}
130130
if (1 >= $i) {
131-
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true);
131+
$file = var_export(implode('/', $file), true);
132132
} else {
133133
$file = array_slice($file, $i);
134-
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file);
135-
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true);
134+
$file = str_repeat('../', count($cacheDir) - $i).implode('/', $file);
135+
$file = '__DIR__.'.var_export('/'.$file, true);
136136
}
137137

138138
$c = "\nnamespace {require $file;}";

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ public function getGroup()
269269
return $this->group;
270270
}
271271

272+
public function getConstraint()
273+
{
274+
return $this->constraint;
275+
}
276+
272277
/**
273278
* {@inheritdoc}
274279
*/

src/Symfony/Component/Validator/Tests/Validator/AbstractTest.php

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

1414
use Symfony\Component\Validator\Constraints\Callback;
15+
use Symfony\Component\Validator\Constraints\Collection;
1516
use Symfony\Component\Validator\Constraints\GroupSequence;
1617
use Symfony\Component\Validator\Constraints\NotNull;
1718
use Symfony\Component\Validator\Constraints\Traverse;
@@ -651,4 +652,22 @@ public function testPassConstraintToViolation()
651652
$this->assertCount(1, $violations);
652653
$this->assertSame($constraint, $violations[0]->getConstraint());
653654
}
655+
656+
public function testCollectionConstraitViolationHasCorrectContext()
657+
{
658+
$data = array(
659+
'foo' => 'fooValue',
660+
);
661+
662+
// Missing field must not be the first in the collection validation
663+
$constraint = new Collection(array(
664+
'foo' => new NotNull(),
665+
'bar' => new NotNull(),
666+
));
667+
668+
$violations = $this->validate($data, $constraint);
669+
670+
$this->assertCount(1, $violations);
671+
$this->assertSame($constraint, $violations[0]->getConstraint());
672+
}
654673
}

src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Constraint;
1515
use Symfony\Component\Validator\Constraints\GroupSequence;
1616
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
17+
use Symfony\Component\Validator\Context\ExecutionContext;
1718
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1819
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1920
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
@@ -110,6 +111,11 @@ public function validate($value, $constraints = null, $groups = null)
110111
$previousMetadata = $this->context->getMetadata();
111112
$previousPath = $this->context->getPropertyPath();
112113
$previousGroup = $this->context->getGroup();
114+
$previousConstraint = null;
115+
116+
if ($this->context instanceof ExecutionContext || method_exists($this->context, 'getConstraint')) {
117+
$previousConstraint = $this->context->getConstraint();
118+
}
113119

114120
// If explicit constraints are passed, validate the value against
115121
// those constraints
@@ -138,6 +144,10 @@ public function validate($value, $constraints = null, $groups = null)
138144
$this->context->setNode($previousValue, $previousObject, $previousMetadata, $previousPath);
139145
$this->context->setGroup($previousGroup);
140146

147+
if (null !== $previousConstraint) {
148+
$this->context->setConstraint($previousConstraint);
149+
}
150+
141151
return $this;
142152
}
143153

0 commit comments

Comments
 (0)
0