Merge branch '4.0'
* 4.0: Fix tests PropertyInfo\DoctrineExtractor - There is bug when indexBy is meta key Fix PercentType error rendering. [minor] SCA [Cache] Inline some hot function calls fixed Silex project's URL fixed deprecations in tests fixed Twig URL [Cache] Add missing `@internal` tag on ProxyTrait fix formatting arguments in plaintext format Fix PSR exception context key Don't assume that file binary exists on *nix OS Fix that ESI/SSI processing can turn a \"private\" response \"public\" [Form] Fixed trimming choice values fix rendering exception stack traces [Routing] Fix loading multiple class annotations for invokable classes
This commit is contained in:
commit
1b1c03af83
@ -95,9 +95,19 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
|
|||||||
|
|
||||||
if (isset($associationMapping['indexBy'])) {
|
if (isset($associationMapping['indexBy'])) {
|
||||||
$indexProperty = $associationMapping['indexBy'];
|
$indexProperty = $associationMapping['indexBy'];
|
||||||
|
/** @var ClassMetadataInfo $subMetadata */
|
||||||
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
||||||
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
|
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
|
||||||
|
|
||||||
|
if (null === $typeOfField) {
|
||||||
|
$associationMapping = $subMetadata->getAssociationMapping($indexProperty);
|
||||||
|
|
||||||
|
/** @var ClassMetadataInfo $subMetadata */
|
||||||
|
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($indexProperty);
|
||||||
|
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
|
||||||
|
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
|
||||||
|
}
|
||||||
|
|
||||||
$collectionKeyType = $this->getPhpType($typeOfField);
|
$collectionKeyType = $this->getPhpType($typeOfField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
'foo',
|
'foo',
|
||||||
'bar',
|
'bar',
|
||||||
'indexedBar',
|
'indexedBar',
|
||||||
|
'indexedFoo',
|
||||||
),
|
),
|
||||||
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
|
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
|
||||||
);
|
);
|
||||||
@ -141,6 +142,14 @@ class DoctrineExtractorTest extends TestCase
|
|||||||
new Type(Type::BUILTIN_TYPE_STRING),
|
new Type(Type::BUILTIN_TYPE_STRING),
|
||||||
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
||||||
))),
|
))),
|
||||||
|
array('indexedFoo', array(new Type(
|
||||||
|
Type::BUILTIN_TYPE_OBJECT,
|
||||||
|
false,
|
||||||
|
'Doctrine\Common\Collections\Collection',
|
||||||
|
true,
|
||||||
|
new Type(Type::BUILTIN_TYPE_STRING),
|
||||||
|
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
|
||||||
|
))),
|
||||||
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
|
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
|
||||||
array('customFoo', null),
|
array('customFoo', null),
|
||||||
array('notMapped', null),
|
array('notMapped', null),
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
|
|||||||
use Doctrine\ORM\Mapping\Column;
|
use Doctrine\ORM\Mapping\Column;
|
||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
use Doctrine\ORM\Mapping\Id;
|
use Doctrine\ORM\Mapping\Id;
|
||||||
|
use Doctrine\ORM\Mapping\OneToMany;
|
||||||
use Doctrine\ORM\Mapping\ManyToMany;
|
use Doctrine\ORM\Mapping\ManyToMany;
|
||||||
use Doctrine\ORM\Mapping\ManyToOne;
|
use Doctrine\ORM\Mapping\ManyToOne;
|
||||||
|
|
||||||
@ -45,6 +46,11 @@ class DoctrineDummy
|
|||||||
*/
|
*/
|
||||||
protected $indexedBar;
|
protected $indexedBar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="foo", indexBy="foo")
|
||||||
|
*/
|
||||||
|
protected $indexedFoo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Column(type="guid")
|
* @Column(type="guid")
|
||||||
*/
|
*/
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
|
|||||||
use Doctrine\ORM\Mapping\Column;
|
use Doctrine\ORM\Mapping\Column;
|
||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
use Doctrine\ORM\Mapping\Id;
|
use Doctrine\ORM\Mapping\Id;
|
||||||
|
use Doctrine\ORM\Mapping\ManyToOne;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
@ -32,4 +33,10 @@ class DoctrineRelation
|
|||||||
* @Column(type="guid")
|
* @Column(type="guid")
|
||||||
*/
|
*/
|
||||||
protected $rguid;
|
protected $rguid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="guid")
|
||||||
|
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
|
||||||
|
*/
|
||||||
|
protected $foo;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
Twig Bridge
|
Twig Bridge
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Provides integration for [Twig](http://twig.sensiolabs.org/) with various
|
Provides integration for [Twig](https://twig.symfony.com/) with various
|
||||||
Symfony components.
|
Symfony components.
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
|
@ -106,8 +106,7 @@
|
|||||||
{%- endblock dateinterval_widget %}
|
{%- endblock dateinterval_widget %}
|
||||||
|
|
||||||
{% block percent_widget -%}
|
{% block percent_widget -%}
|
||||||
<div class="input-group{{ not valid ? ' form-control is-invalid' }}">
|
<div class="input-group">
|
||||||
{% set valid = true %}
|
|
||||||
{{- block('form_widget_simple') -}}
|
{{- block('form_widget_simple') -}}
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<span class="input-group-text">%</span>
|
<span class="input-group-text">%</span>
|
||||||
|
@ -97,11 +97,10 @@ class TemplateFinder implements TemplateFinderInterface
|
|||||||
private function findTemplatesInBundle(BundleInterface $bundle)
|
private function findTemplatesInBundle(BundleInterface $bundle)
|
||||||
{
|
{
|
||||||
$name = $bundle->getName();
|
$name = $bundle->getName();
|
||||||
$templates = array_merge(
|
$templates = array_unique(array_merge(
|
||||||
$this->findTemplatesInFolder($bundle->getPath().'/Resources/views'),
|
$this->findTemplatesInFolder($bundle->getPath().'/Resources/views'),
|
||||||
$this->findTemplatesInFolder($this->rootDir.'/'.$name.'/views')
|
$this->findTemplatesInFolder($this->rootDir.'/'.$name.'/views')
|
||||||
);
|
));
|
||||||
$templates = array_unique($templates);
|
|
||||||
|
|
||||||
foreach ($templates as $i => $template) {
|
foreach ($templates as $i => $template) {
|
||||||
$templates[$i] = $template->set('bundle', $name);
|
$templates[$i] = $template->set('bundle', $name);
|
||||||
|
@ -157,7 +157,7 @@ class CodeHelper extends Helper
|
|||||||
$file = trim($file);
|
$file = trim($file);
|
||||||
$fileStr = $file;
|
$fileStr = $file;
|
||||||
if (0 === strpos($fileStr, $this->rootDir)) {
|
if (0 === strpos($fileStr, $this->rootDir)) {
|
||||||
$fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr));
|
$fileStr = str_replace(array('\\', $this->rootDir), array('/', ''), $fileStr);
|
||||||
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
|
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
|
||||||
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
|
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% if trace.function %}
|
{% if trace.function %}
|
||||||
at {{ trace.class ~ trace.type ~ trace.function }}({{ trace.args|format_args }})
|
at {{ trace.class ~ trace.type ~ trace.function }}({{ trace.args|format_args_as_text }})
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{% if trace.file|default('') is not empty and trace.line|default('') is not empty %}
|
{% if trace.file|default('') is not empty and trace.line|default('') is not empty %}
|
||||||
{{- trace.function ? '\n (' : 'at '}}{{ trace.file|format_file(trace.line)|striptags|replace({ (' at line ' ~ trace.line): '' }) }}:{{ trace.line }}{{ trace.function ? ')' }}
|
{{- trace.function ? '\n (' : 'at '}}{{ trace.file|format_file(trace.line)|striptags|replace({ (' at line ' ~ trace.line): '' }) }}:{{ trace.line }}{{ trace.function ? ')' }}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
{% if exception.trace|length %}
|
{% if exception.trace|length %}
|
||||||
<pre class="stacktrace">
|
|
||||||
{{ exception.class }}:
|
{{ exception.class }}:
|
||||||
{% if exception.message is not empty %}
|
{% if exception.message is not empty %}
|
||||||
{{- exception.message }}
|
{{- exception.message }}
|
||||||
@ -8,5 +7,4 @@
|
|||||||
{% for trace in exception.trace %}
|
{% for trace in exception.trace %}
|
||||||
{{ include('@Twig/Exception/trace.txt.twig', { trace: trace }, with_context = false) }}
|
{{ include('@Twig/Exception/trace.txt.twig', { trace: trace }, with_context = false) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</pre>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -17,7 +17,13 @@
|
|||||||
<tbody id="trace-text-{{ index }}">
|
<tbody id="trace-text-{{ index }}">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{{ include('@Twig/Exception/traces.txt.twig', { exception: exception }, with_context = false) }}
|
{% if exception.trace|length %}
|
||||||
|
<pre class="stacktrace">
|
||||||
|
{%- filter escape('html') -%}
|
||||||
|
{{- include('@Twig/Exception/traces.txt.twig', { exception: exception, format: 'html' }, with_context = false) }}
|
||||||
|
{% endfilter %}
|
||||||
|
</pre>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
<b>Resources</b>
|
<b>Resources</b>
|
||||||
<span>
|
<span>
|
||||||
{% if 'Silex' == collector.applicationname %}
|
{% if 'Silex' == collector.applicationname %}
|
||||||
<a href="http://silex.sensiolabs.org/documentation" rel="help">
|
<a href="https://silex.symfony.com/documentation" rel="help">
|
||||||
Read Silex Docs
|
Read Silex Docs
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -233,7 +233,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
|
|||||||
if (true === $e || array() === $e) {
|
if (true === $e || array() === $e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_array($e) || 1 === count($values)) {
|
if (\is_array($e) || 1 === \count($values)) {
|
||||||
foreach (is_array($e) ? $e : array_keys($values) as $id) {
|
foreach (is_array($e) ? $e : array_keys($values) as $id) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
$v = $values[$id];
|
$v = $values[$id];
|
||||||
|
@ -30,13 +30,13 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
|
|||||||
{
|
{
|
||||||
private $adapters = array();
|
private $adapters = array();
|
||||||
private $adapterCount;
|
private $adapterCount;
|
||||||
private $saveUp;
|
private $syncItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param CacheItemPoolInterface[] $adapters The ordered list of adapters used to fetch cached items
|
* @param CacheItemPoolInterface[] $adapters The ordered list of adapters used to fetch cached items
|
||||||
* @param int $maxLifetime The max lifetime of items propagated from lower adapters to upper ones
|
* @param int $defaultLifetime The default lifetime of items propagated from lower adapters to upper ones
|
||||||
*/
|
*/
|
||||||
public function __construct(array $adapters, int $maxLifetime = 0)
|
public function __construct(array $adapters, int $defaultLifetime = 0)
|
||||||
{
|
{
|
||||||
if (!$adapters) {
|
if (!$adapters) {
|
||||||
throw new InvalidArgumentException('At least one adapter must be specified.');
|
throw new InvalidArgumentException('At least one adapter must be specified.');
|
||||||
@ -55,16 +55,20 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
|
|||||||
}
|
}
|
||||||
$this->adapterCount = count($this->adapters);
|
$this->adapterCount = count($this->adapters);
|
||||||
|
|
||||||
$this->saveUp = \Closure::bind(
|
$this->syncItem = \Closure::bind(
|
||||||
function ($adapter, $item) use ($maxLifetime) {
|
function ($sourceItem, $item) use ($defaultLifetime) {
|
||||||
$origDefaultLifetime = $item->defaultLifetime;
|
$item->value = $sourceItem->value;
|
||||||
|
$item->expiry = $sourceItem->expiry;
|
||||||
|
$item->isHit = $sourceItem->isHit;
|
||||||
|
|
||||||
if (0 < $maxLifetime && ($origDefaultLifetime <= 0 || $maxLifetime < $origDefaultLifetime)) {
|
if (0 < $sourceItem->defaultLifetime && $sourceItem->defaultLifetime < $defaultLifetime) {
|
||||||
$item->defaultLifetime = $maxLifetime;
|
$defaultLifetime = $sourceItem->defaultLifetime;
|
||||||
|
}
|
||||||
|
if (0 < $defaultLifetime && ($item->defaultLifetime <= 0 || $defaultLifetime < $item->defaultLifetime)) {
|
||||||
|
$item->defaultLifetime = $defaultLifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter->save($item);
|
return $item;
|
||||||
$item->defaultLifetime = $origDefaultLifetime;
|
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
CacheItem::class
|
CacheItem::class
|
||||||
@ -76,18 +80,21 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
|
|||||||
*/
|
*/
|
||||||
public function getItem($key)
|
public function getItem($key)
|
||||||
{
|
{
|
||||||
$saveUp = $this->saveUp;
|
$syncItem = $this->syncItem;
|
||||||
|
$misses = array();
|
||||||
|
|
||||||
foreach ($this->adapters as $i => $adapter) {
|
foreach ($this->adapters as $i => $adapter) {
|
||||||
$item = $adapter->getItem($key);
|
$item = $adapter->getItem($key);
|
||||||
|
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
while (0 <= --$i) {
|
while (0 <= --$i) {
|
||||||
$saveUp($this->adapters[$i], $item);
|
$this->adapters[$i]->save($syncItem($item, $misses[$i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$misses[$i] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
@ -104,6 +111,7 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
|
|||||||
private function generateItems($items, $adapterIndex)
|
private function generateItems($items, $adapterIndex)
|
||||||
{
|
{
|
||||||
$missing = array();
|
$missing = array();
|
||||||
|
$misses = array();
|
||||||
$nextAdapterIndex = $adapterIndex + 1;
|
$nextAdapterIndex = $adapterIndex + 1;
|
||||||
$nextAdapter = isset($this->adapters[$nextAdapterIndex]) ? $this->adapters[$nextAdapterIndex] : null;
|
$nextAdapter = isset($this->adapters[$nextAdapterIndex]) ? $this->adapters[$nextAdapterIndex] : null;
|
||||||
|
|
||||||
@ -112,17 +120,18 @@ class ChainAdapter implements AdapterInterface, PruneableInterface, ResettableIn
|
|||||||
yield $k => $item;
|
yield $k => $item;
|
||||||
} else {
|
} else {
|
||||||
$missing[] = $k;
|
$missing[] = $k;
|
||||||
|
$misses[$k] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($missing) {
|
if ($missing) {
|
||||||
$saveUp = $this->saveUp;
|
$syncItem = $this->syncItem;
|
||||||
$adapter = $this->adapters[$adapterIndex];
|
$adapter = $this->adapters[$adapterIndex];
|
||||||
$items = $this->generateItems($nextAdapter->getItems($missing), $nextAdapterIndex);
|
$items = $this->generateItems($nextAdapter->getItems($missing), $nextAdapterIndex);
|
||||||
|
|
||||||
foreach ($items as $k => $item) {
|
foreach ($items as $k => $item) {
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
$saveUp($adapter, $item);
|
$adapter->save($syncItem($item, $misses[$k]));
|
||||||
}
|
}
|
||||||
|
|
||||||
yield $k => $item;
|
yield $k => $item;
|
||||||
|
@ -82,7 +82,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
*/
|
*/
|
||||||
public function getItem($key)
|
public function getItem($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -97,7 +97,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
|
|
||||||
if ('N;' === $value) {
|
if ('N;' === $value) {
|
||||||
$value = null;
|
$value = null;
|
||||||
} elseif (is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
} elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
||||||
try {
|
try {
|
||||||
$e = null;
|
$e = null;
|
||||||
$value = unserialize($value);
|
$value = unserialize($value);
|
||||||
@ -121,7 +121,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
public function getItems(array $keys = array())
|
public function getItems(array $keys = array())
|
||||||
{
|
{
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
*/
|
*/
|
||||||
public function hasItem($key)
|
public function hasItem($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -152,7 +152,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
*/
|
*/
|
||||||
public function deleteItem($key)
|
public function deleteItem($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -171,7 +171,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
$fallbackKeys = array();
|
$fallbackKeys = array();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ class PhpArrayAdapter implements AdapterInterface, PruneableInterface, Resettabl
|
|||||||
|
|
||||||
if ('N;' === $value) {
|
if ('N;' === $value) {
|
||||||
yield $key => $f($key, null, true);
|
yield $key => $f($key, null, true);
|
||||||
} elseif (is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
} elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
||||||
try {
|
try {
|
||||||
yield $key => $f($key, unserialize($value), true);
|
yield $key => $f($key, unserialize($value), true);
|
||||||
} catch (\Error $e) {
|
} catch (\Error $e) {
|
||||||
|
@ -107,7 +107,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface, PruneableInterface, R
|
|||||||
public function invalidateTags(array $tags)
|
public function invalidateTags(array $tags)
|
||||||
{
|
{
|
||||||
foreach ($tags as $k => $tag) {
|
foreach ($tags as $k => $tag) {
|
||||||
if ('' !== $tag && is_string($tag)) {
|
if ('' !== $tag && \is_string($tag)) {
|
||||||
$tags[$k] = $tag.static::TAGS_PREFIX;
|
$tags[$k] = $tag.static::TAGS_PREFIX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface, PruneableInterface, R
|
|||||||
$tagKeys = array();
|
$tagKeys = array();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if ('' !== $key && is_string($key)) {
|
if ('' !== $key && \is_string($key)) {
|
||||||
$key = static::TAGS_PREFIX.$key;
|
$key = static::TAGS_PREFIX.$key;
|
||||||
$tagKeys[$key] = $key;
|
$tagKeys[$key] = $key;
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface, PruneableInterface, R
|
|||||||
public function deleteItems(array $keys)
|
public function deleteItems(array $keys)
|
||||||
{
|
{
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if ('' !== $key && is_string($key)) {
|
if ('' !== $key && \is_string($key)) {
|
||||||
$keys[] = static::TAGS_PREFIX.$key;
|
$keys[] = static::TAGS_PREFIX.$key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ final class CacheItem implements CacheItemInterface
|
|||||||
$this->expiry = $this->defaultLifetime > 0 ? time() + $this->defaultLifetime : null;
|
$this->expiry = $this->defaultLifetime > 0 ? time() + $this->defaultLifetime : null;
|
||||||
} elseif ($time instanceof \DateInterval) {
|
} elseif ($time instanceof \DateInterval) {
|
||||||
$this->expiry = (int) \DateTime::createFromFormat('U', time())->add($time)->format('U');
|
$this->expiry = (int) \DateTime::createFromFormat('U', time())->add($time)->format('U');
|
||||||
} elseif (is_int($time)) {
|
} elseif (\is_int($time)) {
|
||||||
$this->expiry = $time + time();
|
$this->expiry = $time + time();
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given', is_object($time) ? get_class($time) : gettype($time)));
|
throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given', is_object($time) ? get_class($time) : gettype($time)));
|
||||||
@ -109,17 +109,17 @@ final class CacheItem implements CacheItemInterface
|
|||||||
*/
|
*/
|
||||||
public function tag($tags)
|
public function tag($tags)
|
||||||
{
|
{
|
||||||
if (!is_array($tags)) {
|
if (!\is_array($tags)) {
|
||||||
$tags = array($tags);
|
$tags = array($tags);
|
||||||
}
|
}
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
if (!is_string($tag)) {
|
if (!\is_string($tag)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given', is_object($tag) ? get_class($tag) : gettype($tag)));
|
throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given', is_object($tag) ? get_class($tag) : gettype($tag)));
|
||||||
}
|
}
|
||||||
if (isset($this->tags[$tag])) {
|
if (isset($this->tags[$tag])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!isset($tag[0])) {
|
if ('' === $tag) {
|
||||||
throw new InvalidArgumentException('Cache tag length must be greater than zero');
|
throw new InvalidArgumentException('Cache tag length must be greater than zero');
|
||||||
}
|
}
|
||||||
if (false !== strpbrk($tag, '{}()/\@:')) {
|
if (false !== strpbrk($tag, '{}()/\@:')) {
|
||||||
@ -152,10 +152,10 @@ final class CacheItem implements CacheItemInterface
|
|||||||
*/
|
*/
|
||||||
public static function validateKey($key)
|
public static function validateKey($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (!isset($key[0])) {
|
if ('' === $key) {
|
||||||
throw new InvalidArgumentException('Cache key length must be greater than zero');
|
throw new InvalidArgumentException('Cache key length must be greater than zero');
|
||||||
}
|
}
|
||||||
if (false !== strpbrk($key, '{}()/\@:')) {
|
if (false !== strpbrk($key, '{}()/\@:')) {
|
||||||
|
@ -75,7 +75,7 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, Re
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
$ids = array();
|
$ids = array();
|
||||||
@ -99,13 +99,13 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, Re
|
|||||||
*/
|
*/
|
||||||
public function setMultiple($values, $ttl = null)
|
public function setMultiple($values, $ttl = null)
|
||||||
{
|
{
|
||||||
if (!is_array($values) && !$values instanceof \Traversable) {
|
if (!\is_array($values) && !$values instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
||||||
}
|
}
|
||||||
$valuesById = array();
|
$valuesById = array();
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (is_int($key)) {
|
if (\is_int($key)) {
|
||||||
$key = (string) $key;
|
$key = (string) $key;
|
||||||
}
|
}
|
||||||
$valuesById[$this->getId($key)] = $value;
|
$valuesById[$this->getId($key)] = $value;
|
||||||
@ -122,7 +122,7 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, Re
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$keys = array();
|
$keys = array();
|
||||||
foreach (is_array($e) ? $e : array_keys($valuesById) as $id) {
|
foreach (\is_array($e) ? $e : array_keys($valuesById) as $id) {
|
||||||
$keys[] = substr($id, strlen($this->namespace));
|
$keys[] = substr($id, strlen($this->namespace));
|
||||||
}
|
}
|
||||||
CacheItem::log($this->logger, 'Failed to save values', array('keys' => $keys, 'exception' => $e instanceof \Exception ? $e : null));
|
CacheItem::log($this->logger, 'Failed to save values', array('keys' => $keys, 'exception' => $e instanceof \Exception ? $e : null));
|
||||||
@ -137,7 +137,7 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, Re
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, Re
|
|||||||
if ($ttl instanceof \DateInterval) {
|
if ($ttl instanceof \DateInterval) {
|
||||||
$ttl = (int) \DateTime::createFromFormat('U', 0)->add($ttl)->format('U');
|
$ttl = (int) \DateTime::createFromFormat('U', 0)->add($ttl)->format('U');
|
||||||
}
|
}
|
||||||
if (is_int($ttl)) {
|
if (\is_int($ttl)) {
|
||||||
return 0 < $ttl ? $ttl : false;
|
return 0 < $ttl ? $ttl : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class ArrayCache implements CacheInterface, LoggerAwareInterface, ResettableInte
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
@ -72,7 +72,7 @@ class ArrayCache implements CacheInterface, LoggerAwareInterface, ResettableInte
|
|||||||
*/
|
*/
|
||||||
public function deleteMultiple($keys)
|
public function deleteMultiple($keys)
|
||||||
{
|
{
|
||||||
if (!is_array($keys) && !$keys instanceof \Traversable) {
|
if (!\is_array($keys) && !$keys instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
@ -97,13 +97,13 @@ class ArrayCache implements CacheInterface, LoggerAwareInterface, ResettableInte
|
|||||||
*/
|
*/
|
||||||
public function setMultiple($values, $ttl = null)
|
public function setMultiple($values, $ttl = null)
|
||||||
{
|
{
|
||||||
if (!is_array($values) && !$values instanceof \Traversable) {
|
if (!\is_array($values) && !$values instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
||||||
}
|
}
|
||||||
$valuesArray = array();
|
$valuesArray = array();
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
is_int($key) || CacheItem::validateKey($key);
|
\is_int($key) || CacheItem::validateKey($key);
|
||||||
$valuesArray[$key] = $value;
|
$valuesArray[$key] = $value;
|
||||||
}
|
}
|
||||||
if (false === $ttl = $this->normalizeTtl($ttl)) {
|
if (false === $ttl = $this->normalizeTtl($ttl)) {
|
||||||
@ -139,7 +139,7 @@ class ArrayCache implements CacheInterface, LoggerAwareInterface, ResettableInte
|
|||||||
if ($ttl instanceof \DateInterval) {
|
if ($ttl instanceof \DateInterval) {
|
||||||
$ttl = (int) \DateTime::createFromFormat('U', 0)->add($ttl)->format('U');
|
$ttl = (int) \DateTime::createFromFormat('U', 0)->add($ttl)->format('U');
|
||||||
}
|
}
|
||||||
if (is_int($ttl)) {
|
if (\is_int($ttl)) {
|
||||||
return 0 < $ttl ? $ttl : false;
|
return 0 < $ttl ? $ttl : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class ChainCache implements CacheInterface, PruneableInterface, ResettableInterf
|
|||||||
*/
|
*/
|
||||||
public function get($key, $default = null)
|
public function get($key, $default = null)
|
||||||
{
|
{
|
||||||
$miss = null !== $default && is_object($default) ? $default : $this->miss;
|
$miss = null !== $default && \is_object($default) ? $default : $this->miss;
|
||||||
|
|
||||||
foreach ($this->caches as $i => $cache) {
|
foreach ($this->caches as $i => $cache) {
|
||||||
$value = $cache->get($key, $miss);
|
$value = $cache->get($key, $miss);
|
||||||
@ -80,7 +80,7 @@ class ChainCache implements CacheInterface, PruneableInterface, ResettableInterf
|
|||||||
*/
|
*/
|
||||||
public function getMultiple($keys, $default = null)
|
public function getMultiple($keys, $default = null)
|
||||||
{
|
{
|
||||||
$miss = null !== $default && is_object($default) ? $default : $this->miss;
|
$miss = null !== $default && \is_object($default) ? $default : $this->miss;
|
||||||
|
|
||||||
return $this->generateItems($this->caches[0]->getMultiple($keys, $miss), 0, $miss, $default);
|
return $this->generateItems($this->caches[0]->getMultiple($keys, $miss), 0, $miss, $default);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function get($key, $default = null)
|
public function get($key, $default = null)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -75,7 +75,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
|
|
||||||
if ('N;' === $value) {
|
if ('N;' === $value) {
|
||||||
$value = null;
|
$value = null;
|
||||||
} elseif (is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
} elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
||||||
try {
|
try {
|
||||||
$e = null;
|
$e = null;
|
||||||
$value = unserialize($value);
|
$value = unserialize($value);
|
||||||
@ -97,11 +97,11 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function has($key)
|
public function has($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -132,7 +132,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function delete($key)
|
public function delete($key)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -147,7 +147,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function deleteMultiple($keys)
|
public function deleteMultiple($keys)
|
||||||
{
|
{
|
||||||
if (!is_array($keys) && !$keys instanceof \Traversable) {
|
if (!\is_array($keys) && !$keys instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
$fallbackKeys = array();
|
$fallbackKeys = array();
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function set($key, $value, $ttl = null)
|
public function set($key, $value, $ttl = null)
|
||||||
{
|
{
|
||||||
if (!is_string($key)) {
|
if (!\is_string($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
if (null === $this->values) {
|
if (null === $this->values) {
|
||||||
@ -196,7 +196,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
*/
|
*/
|
||||||
public function setMultiple($values, $ttl = null)
|
public function setMultiple($values, $ttl = null)
|
||||||
{
|
{
|
||||||
if (!is_array($values) && !$values instanceof \Traversable) {
|
if (!\is_array($values) && !$values instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
$fallbackValues = array();
|
$fallbackValues = array();
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (!is_string($key) && !is_int($key)) {
|
if (!\is_string($key) && !\is_int($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ class PhpArrayCache implements CacheInterface, PruneableInterface, ResettableInt
|
|||||||
|
|
||||||
if ('N;' === $value) {
|
if ('N;' === $value) {
|
||||||
yield $key => null;
|
yield $key => null;
|
||||||
} elseif (is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
} elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
||||||
try {
|
try {
|
||||||
yield $key => unserialize($value);
|
yield $key => unserialize($value);
|
||||||
} catch (\Error $e) {
|
} catch (\Error $e) {
|
||||||
|
@ -38,7 +38,7 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
|
|||||||
if ($pool instanceof AbstractAdapter) {
|
if ($pool instanceof AbstractAdapter) {
|
||||||
$this->createCacheItem = \Closure::bind(
|
$this->createCacheItem = \Closure::bind(
|
||||||
function ($key, $value, $allowInt = false) {
|
function ($key, $value, $allowInt = false) {
|
||||||
if ($allowInt && is_int($key)) {
|
if ($allowInt && \is_int($key)) {
|
||||||
$key = (string) $key;
|
$key = (string) $key;
|
||||||
} else {
|
} else {
|
||||||
CacheItem::validateKey($key);
|
CacheItem::validateKey($key);
|
||||||
@ -121,7 +121,7 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
|
|||||||
*/
|
*/
|
||||||
public function setMultiple($values, $ttl = null)
|
public function setMultiple($values, $ttl = null)
|
||||||
{
|
{
|
||||||
$valuesIsArray = is_array($values);
|
$valuesIsArray = \is_array($values);
|
||||||
if (!$valuesIsArray && !$values instanceof \Traversable) {
|
if (!$valuesIsArray && !$values instanceof \Traversable) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given', is_object($values) ? get_class($values) : gettype($values)));
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
|
|||||||
$items = $this->pool->getItems($items);
|
$items = $this->pool->getItems($items);
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (is_int($key)) {
|
if (\is_int($key)) {
|
||||||
$key = (string) $key;
|
$key = (string) $key;
|
||||||
}
|
}
|
||||||
$items[$key] = $this->pool->getItem($key)->set($value);
|
$items[$key] = $this->pool->getItem($key)->set($value);
|
||||||
@ -199,7 +199,7 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
|
|||||||
{
|
{
|
||||||
if ($keys instanceof \Traversable) {
|
if ($keys instanceof \Traversable) {
|
||||||
$keys = iterator_to_array($keys, false);
|
$keys = iterator_to_array($keys, false);
|
||||||
} elseif (!is_array($keys)) {
|
} elseif (!\is_array($keys)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given', is_object($keys) ? get_class($keys) : gettype($keys)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class TraceableCache implements CacheInterface, PruneableInterface, ResettableIn
|
|||||||
*/
|
*/
|
||||||
public function get($key, $default = null)
|
public function get($key, $default = null)
|
||||||
{
|
{
|
||||||
$miss = null !== $default && is_object($default) ? $default : $this->miss;
|
$miss = null !== $default && \is_object($default) ? $default : $this->miss;
|
||||||
$event = $this->start(__FUNCTION__);
|
$event = $this->start(__FUNCTION__);
|
||||||
try {
|
try {
|
||||||
$value = $this->pool->get($key, $miss);
|
$value = $this->pool->get($key, $miss);
|
||||||
@ -109,7 +109,7 @@ class TraceableCache implements CacheInterface, PruneableInterface, ResettableIn
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
$values = $values();
|
$values = $values();
|
||||||
} elseif (is_array($values)) {
|
} elseif (\is_array($values)) {
|
||||||
$event->result['keys'] = array_keys($values);
|
$event->result['keys'] = array_keys($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class TraceableCache implements CacheInterface, PruneableInterface, ResettableIn
|
|||||||
*/
|
*/
|
||||||
public function getMultiple($keys, $default = null)
|
public function getMultiple($keys, $default = null)
|
||||||
{
|
{
|
||||||
$miss = null !== $default && is_object($default) ? $default : $this->miss;
|
$miss = null !== $default && \is_object($default) ? $default : $this->miss;
|
||||||
$event = $this->start(__FUNCTION__);
|
$event = $this->start(__FUNCTION__);
|
||||||
try {
|
try {
|
||||||
$result = $this->pool->getMultiple($keys, $miss);
|
$result = $this->pool->getMultiple($keys, $miss);
|
||||||
|
@ -241,7 +241,7 @@ trait AbstractTrait
|
|||||||
if (null === $this->maxIdLength) {
|
if (null === $this->maxIdLength) {
|
||||||
return $this->namespace.$this->namespaceVersion.$key;
|
return $this->namespace.$this->namespaceVersion.$key;
|
||||||
}
|
}
|
||||||
if (strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
|
if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
|
||||||
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), ':', -22);
|
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), ':', -22);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,15 +66,15 @@ return array(
|
|||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
CacheItem::validateKey(is_int($key) ? (string) $key : $key);
|
CacheItem::validateKey(\is_int($key) ? (string) $key : $key);
|
||||||
|
|
||||||
if (null === $value || is_object($value)) {
|
if (null === $value || \is_object($value)) {
|
||||||
try {
|
try {
|
||||||
$value = serialize($value);
|
$value = serialize($value);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, get_class($value)), 0, $e);
|
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, get_class($value)), 0, $e);
|
||||||
}
|
}
|
||||||
} elseif (is_array($value)) {
|
} elseif (\is_array($value)) {
|
||||||
try {
|
try {
|
||||||
$serialized = serialize($value);
|
$serialized = serialize($value);
|
||||||
$unserialized = unserialize($serialized);
|
$unserialized = unserialize($serialized);
|
||||||
@ -85,12 +85,12 @@ EOF;
|
|||||||
if ($unserialized !== $value || (false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized))) {
|
if ($unserialized !== $value || (false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized))) {
|
||||||
$value = $serialized;
|
$value = $serialized;
|
||||||
}
|
}
|
||||||
} elseif (is_string($value)) {
|
} elseif (\is_string($value)) {
|
||||||
// Serialize strings if they could be confused with serialized objects or arrays
|
// Serialize strings if they could be confused with serialized objects or arrays
|
||||||
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
|
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
|
||||||
$value = serialize($value);
|
$value = serialize($value);
|
||||||
}
|
}
|
||||||
} elseif (!is_scalar($value)) {
|
} elseif (!\is_scalar($value)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
|
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ trait PhpFilesTrait
|
|||||||
foreach ($values as $id => $value) {
|
foreach ($values as $id => $value) {
|
||||||
if ('N;' === $value) {
|
if ('N;' === $value) {
|
||||||
$values[$id] = null;
|
$values[$id] = null;
|
||||||
} elseif (is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
} elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
|
||||||
$values[$id] = parent::unserialize($value);
|
$values[$id] = parent::unserialize($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,21 +122,21 @@ trait PhpFilesTrait
|
|||||||
$allowCompile = 'cli' !== PHP_SAPI || ini_get('opcache.enable_cli');
|
$allowCompile = 'cli' !== PHP_SAPI || ini_get('opcache.enable_cli');
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (null === $value || is_object($value)) {
|
if (null === $value || \is_object($value)) {
|
||||||
$value = serialize($value);
|
$value = serialize($value);
|
||||||
} elseif (is_array($value)) {
|
} elseif (\is_array($value)) {
|
||||||
$serialized = serialize($value);
|
$serialized = serialize($value);
|
||||||
$unserialized = parent::unserialize($serialized);
|
$unserialized = parent::unserialize($serialized);
|
||||||
// Store arrays serialized if they contain any objects or references
|
// Store arrays serialized if they contain any objects or references
|
||||||
if ($unserialized !== $value || (false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized))) {
|
if ($unserialized !== $value || (false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized))) {
|
||||||
$value = $serialized;
|
$value = $serialized;
|
||||||
}
|
}
|
||||||
} elseif (is_string($value)) {
|
} elseif (\is_string($value)) {
|
||||||
// Serialize strings if they could be confused with serialized objects or arrays
|
// Serialize strings if they could be confused with serialized objects or arrays
|
||||||
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
|
if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
|
||||||
$value = serialize($value);
|
$value = serialize($value);
|
||||||
}
|
}
|
||||||
} elseif (!is_scalar($value)) {
|
} elseif (!\is_scalar($value)) {
|
||||||
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
|
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ use Symfony\Component\Cache\ResettableInterface;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
trait ProxyTrait
|
trait ProxyTrait
|
||||||
{
|
{
|
||||||
|
@ -240,7 +240,7 @@ trait RedisTrait
|
|||||||
$cursor = null;
|
$cursor = null;
|
||||||
do {
|
do {
|
||||||
$keys = $host instanceof \Predis\Client ? $host->scan($cursor, 'MATCH', $namespace.'*', 'COUNT', 1000) : $host->scan($cursor, $namespace.'*', 1000);
|
$keys = $host instanceof \Predis\Client ? $host->scan($cursor, 'MATCH', $namespace.'*', 'COUNT', 1000) : $host->scan($cursor, $namespace.'*', 1000);
|
||||||
if (isset($keys[1]) && is_array($keys[1])) {
|
if (isset($keys[1]) && \is_array($keys[1])) {
|
||||||
$cursor = $keys[0];
|
$cursor = $keys[0];
|
||||||
$keys = $keys[1];
|
$keys = $keys[1];
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ class JsonDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'name' => '--'.$option->getName(),
|
'name' => '--'.$option->getName(),
|
||||||
'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
|
'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
|
||||||
'accept_value' => $option->acceptValue(),
|
'accept_value' => $option->acceptValue(),
|
||||||
'is_value_required' => $option->isValueRequired(),
|
'is_value_required' => $option->isValueRequired(),
|
||||||
'is_multiple' => $option->isArray(),
|
'is_multiple' => $option->isArray(),
|
||||||
|
@ -70,7 +70,7 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$name = '--'.$option->getName();
|
$name = '--'.$option->getName();
|
||||||
if ($option->getShortcut()) {
|
if ($option->getShortcut()) {
|
||||||
$name .= '|-'.implode('|-', explode('|', $option->getShortcut())).'';
|
$name .= '|-'.str_replace('|', '|-', $option->getShortcut()).'';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->write(
|
$this->write(
|
||||||
|
@ -218,7 +218,7 @@ class XmlDescriptor extends Descriptor
|
|||||||
$pos = strpos($option->getShortcut(), '|');
|
$pos = strpos($option->getShortcut(), '|');
|
||||||
if (false !== $pos) {
|
if (false !== $pos) {
|
||||||
$objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
|
$objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
|
||||||
$objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
|
$objectXML->setAttribute('shortcuts', '-'.str_replace('|', '|-', $option->getShortcut()));
|
||||||
} else {
|
} else {
|
||||||
$objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
|
$objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,10 @@ class ErrorListener implements EventSubscriberInterface
|
|||||||
$error = $event->getError();
|
$error = $event->getError();
|
||||||
|
|
||||||
if (!$inputString = $this->getInputString($event)) {
|
if (!$inputString = $this->getInputString($event)) {
|
||||||
return $this->logger->error('An error occurred while using the console. Message: "{message}"', array('error' => $error, 'message' => $error->getMessage()));
|
return $this->logger->error('An error occurred while using the console. Message: "{message}"', array('exception' => $error, 'message' => $error->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->error('Error thrown while running command "{command}". Message: "{message}"', array('error' => $error, 'command' => $inputString, 'message' => $error->getMessage()));
|
$this->logger->error('Error thrown while running command "{command}". Message: "{message}"', array('exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onConsoleTerminate(ConsoleTerminateEvent $event)
|
public function onConsoleTerminate(ConsoleTerminateEvent $event)
|
||||||
|
@ -195,7 +195,7 @@ class InputOption
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function equals(InputOption $option)
|
public function equals(self $option)
|
||||||
{
|
{
|
||||||
return $option->getName() === $this->getName()
|
return $option->getName() === $this->getName()
|
||||||
&& $option->getShortcut() === $this->getShortcut()
|
&& $option->getShortcut() === $this->getShortcut()
|
||||||
|
@ -34,7 +34,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('error')
|
->method('error')
|
||||||
->with('Error thrown while running command "{command}". Message: "{message}"', array('error' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'))
|
->with('Error thrown while running command "{command}". Message: "{message}"', array('exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$listener = new ErrorListener($logger);
|
$listener = new ErrorListener($logger);
|
||||||
@ -49,7 +49,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('error')
|
->method('error')
|
||||||
->with('An error occurred while using the console. Message: "{message}"', array('error' => $error, 'message' => 'An error occurred'))
|
->with('An error occurred while using the console. Message: "{message}"', array('exception' => $error, 'message' => 'An error occurred'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$listener = new ErrorListener($logger);
|
$listener = new ErrorListener($logger);
|
||||||
|
@ -319,6 +319,7 @@ class ChoiceType extends AbstractType
|
|||||||
// See https://github.com/symfony/symfony/pull/5582
|
// See https://github.com/symfony/symfony/pull/5582
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'choice_translation_domain' => true,
|
'choice_translation_domain' => true,
|
||||||
|
'trim' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||||
|
@ -1880,4 +1880,176 @@ class ChoiceTypeTest extends BaseTypeTest
|
|||||||
'multiple, expanded' => array(true, true, array(array())),
|
'multiple, expanded' => array(true, true, array(array())),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInheritTranslationDomainFromParent()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->add('child', static::TESTED_TYPE)
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassTranslationDomainToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreferOwnTranslationDomain()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
|
'translation_domain' => 'parent_domain',
|
||||||
|
))
|
||||||
|
->add('child', static::TESTED_TYPE, array(
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDefaultTranslationDomain()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', static::TESTED_TYPE)
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertNull($view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassMultipartFalseToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->create(static::TESTED_TYPE, null)
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertFalse($view->vars['multipart']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassLabelToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('__test___field', static::TESTED_TYPE, null, array(
|
||||||
|
'label' => 'My label',
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertSame('My label', $view->vars['label']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToViewWithGrandParent()
|
||||||
|
{
|
||||||
|
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', FormTypeTest::TESTED_TYPE);
|
||||||
|
$builder->get('child')->add('grand_child', static::TESTED_TYPE);
|
||||||
|
$view = $builder->getForm()->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']);
|
||||||
|
$this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']);
|
||||||
|
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToViewWithParent()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', static::TESTED_TYPE)
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('parent_child', $view['child']->vars['id']);
|
||||||
|
$this->assertEquals('child', $view['child']->vars['name']);
|
||||||
|
$this->assertEquals('parent[child]', $view['child']->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassDisabledAsOption()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'disabled' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertTrue($form->isDisabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null)
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('name', $view->vars['id']);
|
||||||
|
$this->assertEquals('name', $view->vars['name']);
|
||||||
|
$this->assertEquals('name', $view->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStripLeadingUnderscoresAndDigitsFromId()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null)
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('name', $view->vars['id']);
|
||||||
|
$this->assertEquals('_09name', $view->vars['name']);
|
||||||
|
$this->assertEquals('_09name', $view->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideTrimCases
|
||||||
|
*/
|
||||||
|
public function testTrimIsDisabled($multiple, $expanded)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'multiple' => $multiple,
|
||||||
|
'expanded' => $expanded,
|
||||||
|
'choices' => array(
|
||||||
|
'a' => '1',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$submittedData = ' 1';
|
||||||
|
|
||||||
|
$form->submit($multiple ? (array) $submittedData : $submittedData);
|
||||||
|
|
||||||
|
// When the choice does not exist the transformation fails
|
||||||
|
$this->assertFalse($form->isSynchronized());
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideTrimCases
|
||||||
|
*/
|
||||||
|
public function testSubmitValueWithWhiteSpace($multiple, $expanded)
|
||||||
|
{
|
||||||
|
$valueWhitWhiteSpace = '1 ';
|
||||||
|
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'multiple' => $multiple,
|
||||||
|
'expanded' => $expanded,
|
||||||
|
'choices' => array(
|
||||||
|
'a' => $valueWhitWhiteSpace,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->submit($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace);
|
||||||
|
|
||||||
|
$this->assertTrue($form->isSynchronized());
|
||||||
|
$this->assertSame($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace, $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideTrimCases()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'Simple' => array(false, false),
|
||||||
|
'Multiple' => array(true, false),
|
||||||
|
'Simple expanded' => array(false, true),
|
||||||
|
'Multiple expanded' => array(true, true),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
"compound",
|
"compound",
|
||||||
"data_class",
|
"data_class",
|
||||||
"empty_data",
|
"empty_data",
|
||||||
"error_bubbling"
|
"error_bubbling",
|
||||||
|
"trim"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"parent": {
|
"parent": {
|
||||||
@ -44,7 +45,6 @@
|
|||||||
"property_path",
|
"property_path",
|
||||||
"required",
|
"required",
|
||||||
"translation_domain",
|
"translation_domain",
|
||||||
"trim",
|
|
||||||
"upload_max_size_message"
|
"upload_max_size_message"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
|
|||||||
choice_name data_class attr csrf_message
|
choice_name data_class attr csrf_message
|
||||||
choice_translation_domain empty_data auto_initialize csrf_protection
|
choice_translation_domain empty_data auto_initialize csrf_protection
|
||||||
choice_value error_bubbling block_name csrf_token_id
|
choice_value error_bubbling block_name csrf_token_id
|
||||||
choices by_reference csrf_token_manager
|
choices trim by_reference csrf_token_manager
|
||||||
expanded data
|
expanded data
|
||||||
group_by disabled
|
group_by disabled
|
||||||
multiple help
|
multiple help
|
||||||
@ -25,7 +25,6 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
|
|||||||
property_path
|
property_path
|
||||||
required
|
required
|
||||||
translation_domain
|
translation_domain
|
||||||
trim
|
|
||||||
upload_max_size_message
|
upload_max_size_message
|
||||||
--------------------------- -------------------- ------------------------- -----------------------
|
--------------------------- -------------------- ------------------------- -----------------------
|
||||||
|
|
||||||
|
@ -43,7 +43,21 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
*/
|
*/
|
||||||
public static function isSupported()
|
public static function isSupported()
|
||||||
{
|
{
|
||||||
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
|
static $supported = null;
|
||||||
|
|
||||||
|
if (null !== $supported) {
|
||||||
|
return $supported;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('passthru') || !function_exists('escapeshellarg')) {
|
||||||
|
return $supported = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
passthru('command -v file', $exitStatus);
|
||||||
|
$binPath = trim(ob_get_clean());
|
||||||
|
|
||||||
|
return $supported = 0 === $exitStatus && '' !== $binPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -502,13 +502,19 @@ class Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the response is worth caching under any circumstance.
|
* Returns true if the response may safely be kept in a shared (surrogate) cache.
|
||||||
*
|
*
|
||||||
* Responses marked "private" with an explicit Cache-Control directive are
|
* Responses marked "private" with an explicit Cache-Control directive are
|
||||||
* considered uncacheable.
|
* considered uncacheable.
|
||||||
*
|
*
|
||||||
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
|
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
|
||||||
* validator (Last-Modified, ETag) are considered uncacheable.
|
* validator (Last-Modified, ETag) are considered uncacheable because there is
|
||||||
|
* no way to tell when or how to remove them from the cache.
|
||||||
|
*
|
||||||
|
* Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
|
||||||
|
* for example "status codes that are defined as cacheable by default [...]
|
||||||
|
* can be reused by a cache with heuristic expiration unless otherwise indicated"
|
||||||
|
* (https://tools.ietf.org/html/rfc7231#section-6.1)
|
||||||
*
|
*
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
|
@ -72,7 +72,7 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
|
|||||||
$response->setLastModified(null);
|
$response->setLastModified(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$response->isFresh()) {
|
if (!$response->isFresh() || !$response->isCacheable()) {
|
||||||
$this->cacheable = false;
|
$this->cacheable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,8 +175,26 @@ class ResponseCacheStrategyTest extends TestCase
|
|||||||
$cacheStrategy->update($masterResponse);
|
$cacheStrategy->update($masterResponse);
|
||||||
|
|
||||||
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
|
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
|
||||||
// Not sure if we should pass "max-age: 60" in this case, as long as the response is private and
|
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
|
||||||
// that's the more conservative of both the master and embedded response...?
|
}
|
||||||
|
|
||||||
|
public function testEmbeddingPublicResponseDoesNotMakeMainResponsePublic()
|
||||||
|
{
|
||||||
|
$cacheStrategy = new ResponseCacheStrategy();
|
||||||
|
|
||||||
|
$masterResponse = new Response();
|
||||||
|
$masterResponse->setPrivate(); // this is the default, but let's be explicit
|
||||||
|
$masterResponse->setMaxAge(100);
|
||||||
|
|
||||||
|
$embeddedResponse = new Response();
|
||||||
|
$embeddedResponse->setPublic();
|
||||||
|
$embeddedResponse->setSharedMaxAge(100);
|
||||||
|
|
||||||
|
$cacheStrategy->add($embeddedResponse);
|
||||||
|
$cacheStrategy->update($masterResponse);
|
||||||
|
|
||||||
|
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
|
||||||
|
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation()
|
public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation()
|
||||||
|
@ -120,12 +120,16 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var $annot RouteAnnotation */
|
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
|
||||||
if (0 === $collection->count() && $class->hasMethod('__invoke') && $annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
|
foreach ($this->reader->getClassAnnotations($class) as $annot) {
|
||||||
$globals['path'] = null;
|
if ($annot instanceof $this->routeAnnotationClass) {
|
||||||
$globals['name'] = '';
|
$globals['path'] = '';
|
||||||
$globals['localized_paths'] = array();
|
$globals['name'] = '';
|
||||||
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
|
$globals['localized_paths'] = array();
|
||||||
|
|
||||||
|
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collection;
|
return $collection;
|
||||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Routing\Tests\Loader;
|
|||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use PHPUnit\Framework\TestCase;
|
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
|
||||||
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
|
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\AbstractClassController;
|
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\AbstractClassController;
|
||||||
@ -35,7 +35,7 @@ use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionLo
|
|||||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionPathController;
|
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionPathController;
|
||||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RouteWithPrefixController;
|
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RouteWithPrefixController;
|
||||||
|
|
||||||
class AnnotationClassLoaderTest extends TestCase
|
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var AnnotationClassLoader
|
* @var AnnotationClassLoader
|
||||||
@ -166,6 +166,51 @@ class AnnotationClassLoaderTest extends TestCase
|
|||||||
$this->assertEquals('/en/action', $routes->get('action.en')->getPath());
|
$this->assertEquals('/en/action', $routes->get('action.en')->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInvokableClassMultipleRouteLoad()
|
||||||
|
{
|
||||||
|
$classRouteData1 = array(
|
||||||
|
'name' => 'route1',
|
||||||
|
'path' => '/1',
|
||||||
|
'schemes' => array('https'),
|
||||||
|
'methods' => array('GET'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$classRouteData2 = array(
|
||||||
|
'name' => 'route2',
|
||||||
|
'path' => '/2',
|
||||||
|
'schemes' => array('https'),
|
||||||
|
'methods' => array('GET'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$reader = $this->getReader();
|
||||||
|
$reader
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getClassAnnotations')
|
||||||
|
->will($this->returnValue(array(new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2))))
|
||||||
|
;
|
||||||
|
$reader
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getMethodAnnotations')
|
||||||
|
->will($this->returnValue(array()))
|
||||||
|
;
|
||||||
|
$loader = new class($reader) extends AnnotationClassLoader {
|
||||||
|
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
$routeCollection = $loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||||
|
$route = $routeCollection->get($classRouteData1['name']);
|
||||||
|
|
||||||
|
$this->assertSame($classRouteData1['path'], $route->getPath(), '->load preserves class route path');
|
||||||
|
$this->assertEquals($classRouteData1['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||||
|
$this->assertEquals($classRouteData1['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||||
|
|
||||||
|
$route = $routeCollection->get($classRouteData2['name']);
|
||||||
|
|
||||||
|
$this->assertSame($classRouteData2['path'], $route->getPath(), '->load preserves class route path');
|
||||||
|
$this->assertEquals($classRouteData2['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||||
|
$this->assertEquals($classRouteData2['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||||
|
}
|
||||||
|
|
||||||
public function testMissingPrefixLocale()
|
public function testMissingPrefixLocale()
|
||||||
{
|
{
|
||||||
$this->expectException(\LogicException::class);
|
$this->expectException(\LogicException::class);
|
||||||
|
@ -29,7 +29,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
|
|
||||||
public function testLoad()
|
public function testLoad()
|
||||||
{
|
{
|
||||||
$this->reader->expects($this->exactly(4))->method('getClassAnnotation');
|
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
|
||||||
|
|
||||||
$this->reader
|
$this->reader
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
@ -37,6 +37,12 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
->will($this->returnValue(array()))
|
->will($this->returnValue(array()))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$this->reader
|
||||||
|
->expects($this->any())
|
||||||
|
->method('getClassAnnotations')
|
||||||
|
->will($this->returnValue(array()))
|
||||||
|
;
|
||||||
|
|
||||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +51,6 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
$this->expectAnnotationsToBeReadFrom(array(
|
$this->expectAnnotationsToBeReadFrom(array(
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
|
||||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -55,6 +60,12 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
->will($this->returnValue(array()))
|
->will($this->returnValue(array()))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$this->reader
|
||||||
|
->expects($this->any())
|
||||||
|
->method('getClassAnnotations')
|
||||||
|
->will($this->returnValue(array()))
|
||||||
|
;
|
||||||
|
|
||||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,10 +160,6 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
|
|||||||
|
|
||||||
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
||||||
|
|
||||||
if (class_exists($class) || interface_exists($class)) {
|
return class_exists($class) || interface_exists($class, false);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user