Merge branch '3.3' into 3.4

* 3.3:
  [PhpUnitBridge] remove unused use statement
  do not mock a deprecated interface
  [DI] Added missing deprecation in changelog
  [Ldap] add a changelog file
  [Security][Serializer][DI] Add new arguments typehints in preparation for 4.0
  [MonologBridge] Fix the Monlog ServerLogHandler from Hanging on Windows
  [DependencyInjection] Fix dumping of RewindableGenerator with empty IteratorArgument
  [DI][Serializer] Fix missing de(normalizer|coder) autoconfig
  Use 0.0.0.0 as the server log host default.
This commit is contained in:
Nicolas Grekas 2017-05-21 10:57:11 +02:00
commit b6fced6261
28 changed files with 97 additions and 48 deletions

View File

@ -303,7 +303,7 @@ Security
* The `RoleInterface` has been deprecated. Extend the `Symfony\Component\Security\Core\Role\Role`
class in your custom role implementations instead.
* The `LogoutUrlGenerator::registerListener()` method will expect a 6th `$context = null` argument in 4.0.
* The `LogoutUrlGenerator::registerListener()` method will expect a 6th `string $context = null` argument in 4.0.
Define the argument when overriding this method.
* The `AccessDecisionManager::setVoters()` method has been deprecated. Pass

View File

@ -426,7 +426,7 @@ Security
* The `RoleInterface` has been removed. Extend the `Symfony\Component\Security\Core\Role\Role`
class instead.
* The `LogoutUrlGenerator::registerListener()` method expects a 6th `$context = null` argument.
* The `LogoutUrlGenerator::registerListener()` method expects a 6th `string $context = null` argument.
* The `AccessDecisionManager::setVoters()` method has been removed. Pass the
voters to the constructor instead.

View File

@ -54,12 +54,12 @@ class ServerLogHandler extends AbstractHandler
$recordFormatted = $this->formatRecord($record);
if (!fwrite($this->socket, $recordFormatted)) {
fclose($this->socket);
if (-1 === stream_socket_sendto($this->socket, $recordFormatted)) {
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
// Let's retry: the persistent connection might just be stale
if ($this->socket = $this->createSocket()) {
fwrite($this->socket, $recordFormatted);
stream_socket_sendto($this->socket, $recordFormatted);
}
}
} finally {

View File

@ -16,7 +16,6 @@ use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Util\Blacklist;
use PHPUnit\Util\Test;
use Symfony\Bridge\PhpUnit\ClockMock;
use Symfony\Bridge\PhpUnit\DnsMock;

View File

@ -49,11 +49,13 @@ use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Validator\ConstraintValidatorInterface;
@ -285,8 +287,12 @@ class FrameworkExtension extends Extension
->addTag('property_info.access_extractor');
$container->registerForAutoconfiguration(EncoderInterface::class)
->addTag('serializer.encoder');
$container->registerForAutoconfiguration(DecoderInterface::class)
->addTag('serializer.encoder');
$container->registerForAutoconfiguration(NormalizerInterface::class)
->addTag('serializer.normalizer');
$container->registerForAutoconfiguration(DenormalizerInterface::class)
->addTag('serializer.normalizer');
$container->registerForAutoconfiguration(ConstraintValidatorInterface::class)
->addTag('validator.constraint_validator');
$container->registerForAutoconfiguration(ObjectInitializerInterface::class)

View File

@ -47,7 +47,7 @@ class ServerLogCommand extends Command
}
$this
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The server host', '0:9911')
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The server host', '0.0.0.0:9911')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The line format', ConsoleFormatter::SIMPLE_FORMAT)
->addOption('date-format', null, InputOption::VALUE_REQUIRED, 'The date format', ConsoleFormatter::SIMPLE_DATE)
->addOption('filter', null, InputOption::VALUE_REQUIRED, 'An expression to filter log. Example: "level > 200 or channel in [\'app\', \'doctrine\']"')

View File

@ -37,6 +37,7 @@ CHANGELOG
* deprecated the ability to set or unset a private service with the `Container::set()` method
* deprecated the ability to check for the existence of a private service with the `Container::has()` method
* deprecated the ability to request a private service with the `Container::get()` method
* deprecated support for generating a dumped `Container` without populating the method map
3.0.0
-----

View File

@ -77,7 +77,7 @@ class Compiler
* @param string $type The type of the pass
* @param int $priority Used to sort the passes
*/
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/)
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/)
{
if (func_num_args() >= 3) {
$priority = func_get_arg(2);
@ -85,7 +85,7 @@ class Compiler
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a third `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s() will have a third `int $priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
}
}

View File

@ -108,7 +108,7 @@ class PassConfig
*
* @throws InvalidArgumentException when a pass type doesn't exist
*/
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/)
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/)
{
if (func_num_args() >= 3) {
$priority = func_get_arg(2);
@ -116,7 +116,7 @@ class PassConfig
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a third `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s() will have a third `int $priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
}
}

View File

@ -86,7 +86,7 @@ class ServiceReferenceGraph
* @param string $reference
* @param bool $lazy
*/
public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null/*, $lazy = false*/)
public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null/*, bool $lazy = false*/)
{
if (func_num_args() >= 6) {
$lazy = func_get_arg(5);
@ -94,7 +94,7 @@ class ServiceReferenceGraph
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a 6th `$lazy = false` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s() will have a 6th `bool $lazy = false` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
}
}
$lazy = false;

View File

@ -448,7 +448,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return $this
*/
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/)
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/)
{
if (func_num_args() >= 3) {
$priority = func_get_arg(2);
@ -456,7 +456,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a third `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s() will have a third `int $priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', __METHOD__), E_USER_DEPRECATED);
}
}

View File

@ -1429,24 +1429,29 @@ EOF;
}
if ($value instanceof IteratorArgument) {
$countCode = array();
$countCode[] = 'function () {';
$operands = array(0);
$code = array();
$code[] = 'new RewindableGenerator(function () {';
foreach ($value->getValues() as $k => $v) {
($c = $this->getServiceConditionals($v)) ? $operands[] = "(int) ($c)" : ++$operands[0];
$v = $this->wrapServiceConditionals($v, sprintf(" yield %s => %s;\n", $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate)));
foreach (explode("\n", $v) as $v) {
if ($v) {
$code[] = ' '.$v;
if (!$values = $value->getValues()) {
$code[] = ' return new \EmptyIterator();';
} else {
$countCode = array();
$countCode[] = 'function () {';
foreach ($values as $k => $v) {
($c = $this->getServiceConditionals($v)) ? $operands[] = "(int) ($c)" : ++$operands[0];
$v = $this->wrapServiceConditionals($v, sprintf(" yield %s => %s;\n", $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate)));
foreach (explode("\n", $v) as $v) {
if ($v) {
$code[] = ' '.$v;
}
}
}
}
$countCode[] = sprintf(' return %s;', implode(' + ', $operands));
$countCode[] = ' }';
$countCode[] = sprintf(' return %s;', implode(' + ', $operands));
$countCode[] = ' }';
}
$code[] = sprintf(' }, %s)', count($operands) > 1 ? implode("\n", $countCode) : $operands[0]);

View File

@ -449,12 +449,17 @@ class ContainerBuilderTest extends TestCase
$builder->register('bar', 'stdClass');
$builder
->register('lazy_context', 'LazyContext')
->setArguments(array(new IteratorArgument(array('k1' => new Reference('bar'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))))
->setArguments(array(
new IteratorArgument(array('k1' => new Reference('bar'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))),
new IteratorArgument(array()),
))
;
$lazyContext = $builder->get('lazy_context');
$this->assertInstanceOf(RewindableGenerator::class, $lazyContext->lazyValues);
$this->assertInstanceOf(RewindableGenerator::class, $lazyContext->lazyEmptyValues);
$this->assertCount(1, $lazyContext->lazyValues);
$this->assertCount(0, $lazyContext->lazyEmptyValues);
$i = 0;
foreach ($lazyContext->lazyValues as $k => $v) {
@ -465,6 +470,13 @@ class ContainerBuilderTest extends TestCase
// The second argument should have been ignored.
$this->assertEquals(1, $i);
$i = 0;
foreach ($lazyContext->lazyEmptyValues as $k => $v) {
++$i;
}
$this->assertEquals(0, $i);
}
/**

View File

@ -436,7 +436,10 @@ class PhpDumperTest extends TestCase
$container->register('lazy_referenced', 'stdClass');
$container
->register('lazy_context', 'LazyContext')
->setArguments(array(new IteratorArgument(array('k1' => new Reference('lazy_referenced'), 'k2' => new Reference('service_container')))))
->setArguments(array(
new IteratorArgument(array('k1' => new Reference('lazy_referenced'), 'k2' => new Reference('service_container'))),
new IteratorArgument(array()),
))
;
$container->compile();
@ -447,6 +450,9 @@ class PhpDumperTest extends TestCase
$lazyContext = $container->get('lazy_context');
$this->assertInstanceOf(RewindableGenerator::class, $lazyContext->lazyValues);
$this->assertInstanceOf(RewindableGenerator::class, $lazyContext->lazyEmptyValues);
$this->assertCount(2, $lazyContext->lazyValues);
$this->assertCount(0, $lazyContext->lazyEmptyValues);
$i = -1;
foreach ($lazyContext->lazyValues as $k => $v) {
@ -461,6 +467,8 @@ class PhpDumperTest extends TestCase
break;
}
}
$this->assertEmpty(iterator_to_array($lazyContext->lazyEmptyValues));
}
public function testClosureProxy()

View File

@ -134,11 +134,11 @@ $container
;
$container
->register('lazy_context', 'LazyContext')
->setArguments(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')))))
->setArguments(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array())))
;
$container
->register('lazy_context_ignore_invalid_ref', 'LazyContext')
->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))))
->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), new IteratorArgument(array())))
;
$container
->register('closure_proxy', 'BarClass')

View File

@ -102,9 +102,11 @@ class DummyProxyDumper implements ProxyDumper
class LazyContext
{
public $lazyValues;
public $lazyEmptyValues;
public function __construct($lazyValues)
public function __construct($lazyValues, $lazyEmptyValues)
{
$this->lazyValues = $lazyValues;
$this->lazyEmptyValues = $lazyEmptyValues;
}
}

View File

@ -323,7 +323,9 @@ class ProjectServiceContainer extends Container
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->get('foo.baz')) && false ?: '_'};
yield 'k2' => $this;
}, 2));
}, 2), new RewindableGenerator(function () {
return new \EmptyIterator();
}, 0));
}
/**
@ -343,7 +345,9 @@ class ProjectServiceContainer extends Container
}
}, function () {
return 1 + (int) ($this->has('invalid'));
}));
}), new RewindableGenerator(function () {
return new \EmptyIterator();
}, 0));
}
/**

View File

@ -326,7 +326,9 @@ class ProjectServiceContainer extends Container
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->get('foo.baz')) && false ?: '_'};
yield 'k2' => $this;
}, 2));
}, 2), new RewindableGenerator(function () {
return new \EmptyIterator();
}, 0));
}
/**
@ -341,7 +343,9 @@ class ProjectServiceContainer extends Container
{
return $this->services['lazy_context_ignore_invalid_ref'] = new \LazyContext(new RewindableGenerator(function () {
yield 0 => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->get('foo.baz')) && false ?: '_'};
}, 1));
}, 1), new RewindableGenerator(function () {
return new \EmptyIterator();
}, 0));
}
/**

View File

@ -121,12 +121,14 @@
<argument key="k1" type="service" id="foo.baz"/>
<argument key="k2" type="service" id="service_container"/>
</argument>
<argument type="iterator"/>
</service>
<service id="lazy_context_ignore_invalid_ref" class="LazyContext">
<argument type="iterator">
<argument type="service" id="foo.baz"/>
<argument type="service" id="invalid" on-invalid="ignore"/>
</argument>
<argument type="iterator"/>
</service>
<service id="closure_proxy" class="BarClass">
<argument type="closure-proxy" id="closure_proxy" method="getBaz"/>

View File

@ -112,10 +112,10 @@ services:
factory: ['@factory_simple', getInstance]
lazy_context:
class: LazyContext
arguments: [!iterator {'k1': '@foo.baz', 'k2': '@service_container'}]
arguments: [!iterator {'k1': '@foo.baz', 'k2': '@service_container'}, !iterator []]
lazy_context_ignore_invalid_ref:
class: LazyContext
arguments: [!iterator ['@foo.baz', '@?invalid']]
arguments: [!iterator ['@foo.baz', '@?invalid'], !iterator []]
closure_proxy:
class: BarClass
arguments: [!closure_proxy ['@closure_proxy', getBaz]]

View File

@ -273,7 +273,7 @@ class XmlFileLoaderTest extends TestCase
$lazyDefinition = $container->getDefinition('lazy_context');
$this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')))), $lazyDefinition->getArguments(), '->load() parses lazy arguments');
$this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array())), $lazyDefinition->getArguments(), '->load() parses lazy arguments');
}
public function testParsesTags()
@ -659,7 +659,6 @@ class XmlFileLoaderTest extends TestCase
$this->assertFalse($container->getDefinition('no_defaults')->isAutowired());
$this->assertTrue($container->getDefinition('child_def')->isPublic());
$this->assertSame(array('foo' => array(array())), $container->getDefinition('child_def')->getTags());
$this->assertFalse($container->getDefinition('child_def')->isAutowired());

View File

@ -346,7 +346,7 @@ class YamlFileLoaderTest extends TestCase
$lazyDefinition = $container->getDefinition('lazy_context');
$this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')))), $lazyDefinition->getArguments(), '->load() parses lazy arguments');
$this->assertEquals(array(new IteratorArgument(array('k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container'))), new IteratorArgument(array())), $lazyDefinition->getArguments(), '->load() parses lazy arguments');
}
public function testAutowire()

View File

@ -0,0 +1,7 @@
CHANGELOG
=========
3.1.0
-----
* The `LdapClient` class is deprecated. Use the `Ldap` class instead.

View File

@ -18,7 +18,7 @@ namespace Symfony\Component\Ldap;
* @author Francis Besset <francis.besset@gmail.com>
* @author Charles Sarrazin <charles@sarraz.in>
*
* @deprecated The LdapClient class will be removed in Symfony 4.0. You should use the Ldap class instead.
* @deprecated since version 3.1, to be removed in 4.0. Use the Ldap class instead.
*/
final class LdapClient implements LdapClientInterface
{

View File

@ -19,7 +19,7 @@ namespace Symfony\Component\Ldap;
* @author Grégoire Pineau <lyrixx@lyrixx.info>
* @author Charles Sarrazin <charles@sarraz.in>
*
* @deprecated You should use LdapInterface instead
* @deprecated since version 3.1, to be removed in 4.0. Use the LdapInterface instead.
*/
interface LdapClientInterface extends LdapInterface
{

View File

@ -35,7 +35,7 @@ class LdapBindAuthenticationProviderTest extends TestCase
public function testEmptyPasswordShouldThrowAnException()
{
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);

View File

@ -48,7 +48,7 @@ class LogoutUrlGenerator
* @param CsrfTokenManagerInterface|null $csrfTokenManager A CsrfTokenManagerInterface instance
* @param string|null $context The listener context
*/
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, CsrfTokenManagerInterface $csrfTokenManager = null/*, $context = null*/)
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, CsrfTokenManagerInterface $csrfTokenManager = null/*, string $context = null*/)
{
if (func_num_args() >= 6) {
$context = func_get_arg(5);
@ -56,7 +56,7 @@ class LogoutUrlGenerator
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a sixth `$context = null` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s() will have a sixth `string $context = null` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
}
}

View File

@ -302,7 +302,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
*
* @throws RuntimeException
*/
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes/*, $format = null*/)
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes/*, string $format = null*/)
{
if (func_num_args() >= 6) {
$format = func_get_arg(5);
@ -310,7 +310,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
if (__CLASS__ !== get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s::%s() will have a 6th `$format = null` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
@trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
}
}