Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  Typo fix
  [2.3] Static Code Analysis for Components
  Added support \IteratorAggregate for UniqueEntityValidator
  Fix #17306 Paths with % in it are note allowed (like urlencoded)
  Added sort order SORT_STRING for params in UriSigner
  Remove normalizer cache in Serializer class
  • Loading branch information
fabpot committed Jan 12, 2016
2 parents ab00f68 + 406e260 commit da655a9
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 53 deletions.
4 changes: 2 additions & 2 deletions UPGRADE-3.0.md
Expand Up @@ -10,8 +10,8 @@ UPGRADE FROM 2.x to 3.0
| -------- | ---
| `registerNamespaces()` | `addPrefixes()`
| `registerPrefixes()` | `addPrefixes()`
| `registerNamespaces()` | `addPrefix()`
| `registerPrefixes()` | `addPrefix()`
| `registerNamespace()` | `addPrefix()`
| `registerPrefix()` | `addPrefix()`
| `getNamespaces()` | `getPrefixes()`
| `getNamespaceFallbacks()` | `getFallbackDirs()`
| `getPrefixFallbacks()` | `getFallbackDirs()`
Expand Down
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
Expand Down Expand Up @@ -336,6 +337,44 @@ public function testValidateUniquenessWithUnrewoundArray()
$this->assertNoViolation();
}

/**
* @dataProvider resultTypesProvider
*/
public function testValidateResultTypes($entity1, $result)
{
$constraint = new UniqueEntity(array(
'message' => 'myMessage',
'fields' => array('name'),
'em' => self::EM_NAME,
'repositoryMethod' => 'findByCustom',
));

$repository = $this->createRepositoryMock();
$repository->expects($this->once())
->method('findByCustom')
->will($this->returnValue($result))
;
$this->em = $this->createEntityManagerMock($repository);
$this->registry = $this->createRegistryMock($this->em);
$this->validator = $this->createValidator();
$this->validator->initialize($this->context);

$this->validator->validate($entity1, $constraint);

$this->assertNoViolation();
}

public function resultTypesProvider()
{
$entity = new SingleIntIdEntity(1, 'foo');

return array(
array($entity, array($entity)),
array($entity, new \ArrayIterator(array($entity))),
array($entity, new ArrayCollection(array($entity))),
);
}

public function testAssociatedEntity()
{
$constraint = new UniqueEntity(array(
Expand Down
Expand Up @@ -114,6 +114,10 @@ public function validate($entity, Constraint $constraint)
$repository = $em->getRepository(get_class($entity));
$result = $repository->{$constraint->repositoryMethod}($criteria);

if ($result instanceof \IteratorAggregate) {
$result = $result->getIterator();
}

/* If the result is a MongoCursor, it must be advanced to the first
* element. Rewinding should have no ill effect if $result is another
* iterator implementation.
Expand Down
Expand Up @@ -685,17 +685,17 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
}
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
$rootDir = $container->getParameter('kernel.root_dir');
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
$dirs[] = $dir;
}
if (is_dir($dir = sprintf($overridePath, $bundle))) {
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
$dirs[] = $dir;
}
}
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
if (is_dir($dir = $rootDir.'/Resources/translations')) {
$dirs[] = $dir;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -129,7 +129,7 @@ public function setServerParameter($key, $value)
*/
public function getServerParameter($key, $default = '')
{
return (isset($this->server[$key])) ? $this->server[$key] : $default;
return isset($this->server[$key]) ? $this->server[$key] : $default;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/TableHelper.php
Expand Up @@ -69,7 +69,7 @@ public function setLayout($layout)

default:
throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
};
}

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Output/ConsoleOutput.php
Expand Up @@ -131,7 +131,7 @@ function_exists('php_uname') ? php_uname('s') : '',
PHP_OS,
);

return false !== stristr(implode(';', $checks), 'OS400');
return false !== stripos(implode(';', $checks), 'OS400');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -534,6 +534,6 @@ public static function camelize($id)
*/
public static function underscore($id)
{
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id)));
}
}
Expand Up @@ -91,9 +91,7 @@ public function getConfiguration(array $config, ContainerBuilder $container)
$container->addResource(new FileResource($r->getFileName()));

if (!method_exists($class, '__construct')) {
$configuration = new $class();

return $configuration;
return new $class();
}
}
}
Expand Down
Expand Up @@ -93,8 +93,9 @@ private function parseImports(\DOMDocument $xml, $file)
return;
}

$defaultDirectory = dirname($file);
foreach ($imports as $import) {
$this->setCurrentDir(dirname($file));
$this->setCurrentDir($defaultDirectory);
$this->import($import->getAttribute('resource'), null, (bool) XmlUtils::phpize($import->getAttribute('ignore-errors')), $file);
}
}
Expand Down
Expand Up @@ -95,12 +95,13 @@ private function parseImports($content, $file)
throw new InvalidArgumentException(sprintf('The "imports" key should contain an array in %s. Check your YAML syntax.', $file));
}

$defaultDirectory = dirname($file);
foreach ($content['imports'] as $import) {
if (!is_array($import)) {
throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file));
}

$this->setCurrentDir(dirname($file));
$this->setCurrentDir($defaultDirectory);
$this->import($import['resource'], null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -446,7 +446,7 @@ public function isAbsolutePath($file)
return strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& substr($file, 1, 1) === ':'
&& (strspn($file, '/\\', 2, 1))
&& strspn($file, '/\\', 2, 1)
)
|| null !== parse_url($file, PHP_URL_SCHEME)
;
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/HttpFoundation/HeaderBag.php
Expand Up @@ -111,7 +111,7 @@ public function add(array $headers)
*/
public function get($key, $default = null, $first = true)
{
$key = strtr(strtolower($key), '_', '-');
$key = str_replace('_', '-', strtolower($key));

if (!array_key_exists($key, $this->headers)) {
if (null === $default) {
Expand All @@ -137,7 +137,7 @@ public function get($key, $default = null, $first = true)
*/
public function set($key, $values, $replace = true)
{
$key = strtr(strtolower($key), '_', '-');
$key = str_replace('_', '-', strtolower($key));

$values = array_values((array) $values);

Expand All @@ -161,7 +161,7 @@ public function set($key, $values, $replace = true)
*/
public function has($key)
{
return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
return array_key_exists(str_replace('_', '-', strtolower($key)), $this->headers);
}

/**
Expand All @@ -184,7 +184,7 @@ public function contains($key, $value)
*/
public function remove($key)
{
$key = strtr(strtolower($key), '_', '-');
$key = str_replace('_', '-', strtolower($key));

unset($this->headers[$key]);

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
Expand Up @@ -99,7 +99,7 @@ public function set($key, $values, $replace = true)
{
parent::set($key, $values, $replace);

$uniqueKey = strtr(strtolower($key), '_', '-');
$uniqueKey = str_replace('_', '-', strtolower($key));
$this->headerNames[$uniqueKey] = $key;

// ensure the cache-control header has sensible defaults
Expand All @@ -118,7 +118,7 @@ public function remove($key)
{
parent::remove($key);

$uniqueKey = strtr(strtolower($key), '_', '-');
$uniqueKey = str_replace('_', '-', strtolower($key));
unset($this->headerNames[$uniqueKey]);

if ('cache-control' === $uniqueKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -177,7 +177,7 @@ public function registerCommands(Application $application)
foreach ($finder as $file) {
$ns = $prefix;
if ($relativePath = $file->getRelativePath()) {
$ns .= '\\'.strtr($relativePath, '/', '\\');
$ns .= '\\'.str_replace('/', '\\', $relativePath);
}
$class = $ns.'\\'.$file->getBasename('.php');
if ($this->container) {
Expand Down
14 changes: 5 additions & 9 deletions src/Symfony/Component/HttpKernel/HttpCache/Store.php
Expand Up @@ -38,10 +38,8 @@ class Store implements StoreInterface
public function __construct($root)
{
$this->root = $root;
if (!is_dir($this->root)) {
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
}
if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
}
$this->keyCache = new \SplObjectStorage();
$this->locks = array();
Expand Down Expand Up @@ -249,10 +247,8 @@ public function invalidate(Request $request)
}
}

if ($modified) {
if (false === $this->save($key, serialize($entries))) {
throw new \RuntimeException('Unable to store the metadata.');
}
if ($modified && false === $this->save($key, serialize($entries))) {
throw new \RuntimeException('Unable to store the metadata.');
}
}

Expand All @@ -273,7 +269,7 @@ private function requestsMatch($vary, $env1, $env2)
}

foreach (preg_split('/[\s,]+/', $vary) as $header) {
$key = strtr(strtolower($header), '_', '-');
$key = str_replace('_', '-', strtolower($header));
$v1 = isset($env1[$key]) ? $env1[$key] : null;
$v2 = isset($env2[$key]) ? $env2[$key] : null;
if ($v1 !== $v2) {
Expand Down
Expand Up @@ -188,9 +188,8 @@ protected function fetch($db, $query, array $args = array())
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$stmt->execute();
$return = $stmt->fetchAll(\PDO::FETCH_ASSOC);

return $return;
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}

protected function close($db)
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php
Expand Up @@ -33,6 +33,7 @@ public function testCheck()

$this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer')));

$this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/UriSigner.php
Expand Up @@ -51,7 +51,7 @@ public function sign($uri)

$uri = $this->buildUrl($url, $params);

return $uri.(false === (strpos($uri, '?')) ? '?' : '&').'_hash='.$this->computeHash($uri);
return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri);
}

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ private function computeHash($uri)

private function buildUrl(array $url, array $params = array())
{
ksort($params);
ksort($params, SORT_STRING);
$url['query'] = http_build_query($params, '', '&');

$scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
Expand Down
Expand Up @@ -171,10 +171,8 @@ public function validateAndDecode($entryPointKey, $expectedRealm)
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s" (%s)', $this->header, implode(', ', $keys)));
}

if ('auth' === $this->elements['qop']) {
if (!isset($this->elements['nc']) || !isset($this->elements['cnonce'])) {
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
}
if ('auth' === $this->elements['qop'] && !isset($this->elements['nc'], $this->elements['cnonce'])) {
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
}

if ($expectedRealm !== $this->elements['realm']) {
Expand Down
23 changes: 10 additions & 13 deletions src/Symfony/Component/Serializer/Serializer.php
Expand Up @@ -187,17 +187,10 @@ private function getNormalizer($data, $format)
{
if ($isObject = is_object($data)) {
$class = get_class($data);
if (isset($this->normalizerCache[$class][$format])) {
return $this->normalizerCache[$class][$format];
}
}

foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) {
if ($isObject) {
$this->normalizerCache[$class][$format] = $normalizer;
}

return $normalizer;
}
}
Expand All @@ -214,14 +207,8 @@ private function getNormalizer($data, $format)
*/
private function getDenormalizer($data, $class, $format)
{
if (isset($this->denormalizerCache[$class][$format])) {
return $this->denormalizerCache[$class][$format];
}

foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format)) {
$this->denormalizerCache[$class][$format] = $normalizer;

return $normalizer;
}
}
Expand Down Expand Up @@ -264,6 +251,7 @@ private function normalizeObject($object, $format, array $context = array())
if ($normalizer = $this->getNormalizer($object, $format)) {
return $normalizer->normalize($object, $format, $context);
}

throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($object)));
}

Expand All @@ -289,6 +277,15 @@ private function denormalizeObject($data, $class, $format, array $context = arra
if ($normalizer = $this->getDenormalizer($data, $class, $format)) {
return $normalizer->denormalize($data, $class, $format, $context);
}

foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof DenormalizerInterface
&& $normalizer->supportsDenormalization($data, $class, $format)) {

return $normalizer->denormalize($data, $class, $format, $context);
}
}

throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
}

Expand Down

0 comments on commit da655a9

Please sign in to comment.