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

Skip to content

Commit d3014e4

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [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 cae4755 + 49addbe commit d3014e4

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
@@ -73,7 +73,7 @@
7373
{% for name, template in templates %}
7474
{% set menu -%}
7575
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
76-
{{ block('menu', template) }}
76+
{{- block('menu', template) -}}
7777
{% endwith %}
7878
{%- endset %}
7979
{% 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
@@ -63,7 +63,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
6363
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
6464
}
6565
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
66-
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
66+
$cache = $cacheDir.'/'.$name.$extension;
6767

6868
// auto-reload
6969
$reload = false;
@@ -114,7 +114,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
114114
REGEX;
115115
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
116116

117-
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
117+
$cacheDir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $cacheDir));
118118
$files = array();
119119
$content = '';
120120
foreach (self::getOrderedClasses($classes) as $class) {
@@ -126,19 +126,19 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
126126
$c = file_get_contents($file);
127127

128128
if (preg_match($dontInlineRegex, $c)) {
129-
$file = explode(DIRECTORY_SEPARATOR, $file);
129+
$file = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $file));
130130

131131
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
132132
if ($file[$i] !== $cacheDir[$i]) {
133133
break;
134134
}
135135
}
136136
if (1 >= $i) {
137-
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true);
137+
$file = var_export(implode('/', $file), true);
138138
} else {
139139
$file = array_slice($file, $i);
140-
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file);
141-
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true);
140+
$file = str_repeat('../', count($cacheDir) - $i).implode('/', $file);
141+
$file = '__DIR__.'.var_export('/'.$file, true);
142142
}
143143

144144
$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
@@ -287,6 +287,11 @@ public function getGroup()
287287
return $this->group;
288288
}
289289

290+
public function getConstraint()
291+
{
292+
return $this->constraint;
293+
}
294+
290295
/**
291296
* {@inheritdoc}
292297
*/

src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.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;
@@ -720,4 +721,22 @@ public function testPassConstraintToViolation()
720721
$this->assertCount(1, $violations);
721722
$this->assertSame($constraint, $violations[0]->getConstraint());
722723
}
724+
725+
public function testCollectionConstraitViolationHasCorrectContext()
726+
{
727+
$data = array(
728+
'foo' => 'fooValue',
729+
);
730+
731+
// Missing field must not be the first in the collection validation
732+
$constraint = new Collection(array(
733+
'foo' => new NotNull(),
734+
'bar' => new NotNull(),
735+
));
736+
737+
$violations = $this->validate($data, $constraint);
738+
739+
$this->assertCount(1, $vi F438 olations);
740+
$this->assertSame($constraint, $violations[0]->getConstraint());
741+
}
723742
}

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