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
This commit is contained in:
Fabien Potencier 2016-11-29 09:26:03 +01:00
commit 27e2b9d957
5 changed files with 41 additions and 7 deletions

View File

@ -114,7 +114,7 @@
{% for name, template in templates %} {% for name, template in templates %}
{% set menu -%} {% set menu -%}
{% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %} {% with { collector: profile.getcollector(name), profiler_markup_version: profiler_markup_version } %}
{{ block('menu', template) }} {{- block('menu', template) -}}
{% endwith %} {% endwith %}
{%- endset %} {%- endset %}
{% if menu is not empty %} {% if menu is not empty %}

View File

@ -60,7 +60,7 @@ class ClassCollectionLoader
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir)); throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
} }
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR); $cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension; $cache = $cacheDir.'/'.$name.$extension;
// auto-reload // auto-reload
$reload = false; $reload = false;
@ -108,7 +108,7 @@ class ClassCollectionLoader
REGEX; REGEX;
$dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex); $dontInlineRegex = str_replace('.', $spacesRegex, $dontInlineRegex);
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir); $cacheDir = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $cacheDir));
$files = array(); $files = array();
$content = ''; $content = '';
foreach (self::getOrderedClasses($classes) as $class) { foreach (self::getOrderedClasses($classes) as $class) {
@ -120,7 +120,7 @@ REGEX;
$c = file_get_contents($file); $c = file_get_contents($file);
if (preg_match($dontInlineRegex, $c)) { if (preg_match($dontInlineRegex, $c)) {
$file = explode(DIRECTORY_SEPARATOR, $file); $file = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $file));
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) { for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
if ($file[$i] !== $cacheDir[$i]) { if ($file[$i] !== $cacheDir[$i]) {
@ -128,11 +128,11 @@ REGEX;
} }
} }
if (1 >= $i) { if (1 >= $i) {
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true); $file = var_export(implode('/', $file), true);
} else { } else {
$file = array_slice($file, $i); $file = array_slice($file, $i);
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file); $file = str_repeat('../', count($cacheDir) - $i).implode('/', $file);
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true); $file = '__DIR__.'.var_export('/'.$file, true);
} }
$c = "\nnamespace {require $file;}"; $c = "\nnamespace {require $file;}";

View File

@ -269,6 +269,11 @@ class ExecutionContext implements ExecutionContextInterface
return $this->group; return $this->group;
} }
public function getConstraint()
{
return $this->constraint;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests\Validator; namespace Symfony\Component\Validator\Tests\Validator;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Traverse; use Symfony\Component\Validator\Constraints\Traverse;
@ -651,4 +652,22 @@ abstract class AbstractTest extends AbstractValidatorTest
$this->assertCount(1, $violations); $this->assertCount(1, $violations);
$this->assertSame($constraint, $violations[0]->getConstraint()); $this->assertSame($constraint, $violations[0]->getConstraint());
} }
public function testCollectionConstraitViolationHasCorrectContext()
{
$data = array(
'foo' => 'fooValue',
);
// Missing field must not be the first in the collection validation
$constraint = new Collection(array(
'foo' => new NotNull(),
'bar' => new NotNull(),
));
$violations = $this->validate($data, $constraint);
$this->assertCount(1, $violations);
$this->assertSame($constraint, $violations[0]->getConstraint());
}
} }

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\Context\ExecutionContext;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Exception\NoSuchMetadataException; use Symfony\Component\Validator\Exception\NoSuchMetadataException;
@ -110,6 +111,11 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
$previousMetadata = $this->context->getMetadata(); $previousMetadata = $this->context->getMetadata();
$previousPath = $this->context->getPropertyPath(); $previousPath = $this->context->getPropertyPath();
$previousGroup = $this->context->getGroup(); $previousGroup = $this->context->getGroup();
$previousConstraint = null;
if ($this->context instanceof ExecutionContext || method_exists($this->context, 'getConstraint')) {
$previousConstraint = $this->context->getConstraint();
}
// If explicit constraints are passed, validate the value against // If explicit constraints are passed, validate the value against
// those constraints // those constraints
@ -138,6 +144,10 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
$this->context->setNode($previousValue, $previousObject, $previousMetadata, $previousPath); $this->context->setNode($previousValue, $previousObject, $previousMetadata, $previousPath);
$this->context->setGroup($previousGroup); $this->context->setGroup($previousGroup);
if (null !== $previousConstraint) {
$this->context->setConstraint($previousConstraint);
}
return $this; return $this;
} }