Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,68 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Mapping\Factory;
use Psr\Cache\CacheItemPoolInterface;
/**
* Caches metadata using a PSR-6 implementation.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
{
use ClassResolverTrait;
/**
* @var ClassMetadataFactoryInterface
*/
private $decorated;
/**
* @var CacheItemPoolInterface
*/
private $cacheItemPool;
public function __construct(ClassMetadataFactoryInterface $decorated, CacheItemPoolInterface $cacheItemPool)
{
$this->decorated = $decorated;
$this->cacheItemPool = $cacheItemPool;
}
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
$class = $this->getClass($value);
// Key cannot contain backslashes according to PSR-6
$key = strtr($class, '\\', '_');
$item = $this->cacheItemPool->getItem($key);
if ($item->isHit()) {
return $item->get();
}
$metadata = $this->decorated->getMetadataFor($value);
$this->cacheItemPool->save($item->set($metadata));
return $metadata;
}
/**
* {@inheritdoc}
*/
public function hasMetadataFor($value)
{
return $this->decorated->hasMetadataFor($value);
}
}

View file

@ -0,0 +1,94 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Mapping\Factory;
use Doctrine\Common\Cache\Cache;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
/**
* Returns a {@link ClassMetadata}.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ClassMetadataFactory implements ClassMetadataFactoryInterface
{
use ClassResolverTrait;
private $loader;
private $cache;
private $loadedClasses;
public function __construct(LoaderInterface $loader, Cache $cache = null)
{
$this->loader = $loader;
$this->cache = $cache;
if (null !== $cache) {
@trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since Symfony 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), E_USER_DEPRECATED);
}
}
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
$class = $this->getClass($value);
if (isset($this->loadedClasses[$class])) {
return $this->loadedClasses[$class];
}
if ($this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) {
return $this->loadedClasses[$class];
}
$classMetadata = new ClassMetadata($class);
$this->loader->loadClassMetadata($classMetadata);
$reflectionClass = $classMetadata->getReflectionClass();
// Include metadata from the parent class
if ($parent = $reflectionClass->getParentClass()) {
$classMetadata->merge($this->getMetadataFor($parent->name));
}
// Include metadata from all implemented interfaces
foreach ($reflectionClass->getInterfaces() as $interface) {
$classMetadata->merge($this->getMetadataFor($interface->name));
}
if ($this->cache) {
$this->cache->save($class, $classMetadata);
}
return $this->loadedClasses[$class] = $classMetadata;
}
/**
* {@inheritdoc}
*/
public function hasMetadataFor($value)
{
try {
$this->getClass($value);
return true;
} catch (InvalidArgumentException $invalidArgumentException) {
// Return false in case of exception
}
return false;
}
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Mapping\Factory;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
/**
* Returns a {@see ClassMetadataInterface}.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
interface ClassMetadataFactoryInterface
{
/**
* If the method was called with the same class name (or an object of that
* class) before, the same metadata instance is returned.
*
* If the factory was configured with a cache, this method will first look
* for an existing metadata instance in the cache. If an existing instance
* is found, it will be returned without further ado.
*
* Otherwise, a new metadata instance is created. If the factory was
* configured with a loader, the metadata is passed to the
* {@link \Symfony\Component\Serializer\Mapping\Loader\LoaderInterface::loadClassMetadata()} method for further
* configuration. At last, the new object is returned.
*
* @param string|object $value
*
* @return ClassMetadataInterface
*
* @throws InvalidArgumentException
*/
public function getMetadataFor($value);
/**
* Checks if class has metadata.
*
* @param mixed $value
*
* @return bool
*/
public function hasMetadataFor($value);
}

View file

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Mapping\Factory;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* Resolves a class name.
*
* @internal
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
trait ClassResolverTrait
{
/**
* Gets a class name for a given class or instance.
*
* @param mixed $value
*
* @return string
*
* @throws InvalidArgumentException If the class does not exists
*/
private function getClass($value)
{
if (\is_string($value)) {
if (!class_exists($value) && !interface_exists($value)) {
throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
}
return ltrim($value, '\\');
}
if (!\is_object($value)) {
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value)));
}
return \get_class($value);
}
}