minor #23801 Continuation of #23624 (ro0NL)

This PR was squashed before being merged into the 3.4 branch (closes #23801).

Discussion
----------

Continuation of #23624

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

See https://github.com/symfony/symfony/pull/23624#discussion_r131539736

cc @chalasr

Also included service injection for init:acl + set:acl and simplification of lint:xliff + lintt:yaml.

Btw, i think init:acl needs to be renamed to acl:init :)

Commits
-------

5f637c1 Continuation of #23624
This commit is contained in:
Nicolas Grekas 2017-08-06 20:13:25 +02:00
commit 266d9d375e
19 changed files with 184 additions and 138 deletions

View File

@ -33,16 +33,16 @@ class DebugCommand extends Command
*/ */
public function __construct($twig = null) public function __construct($twig = null)
{ {
parent::__construct();
if (!$twig instanceof Environment) { if (!$twig instanceof Environment) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $twig ? 'debug:twig' : $twig); parent::__construct($twig);
return; return;
} }
parent::__construct();
$this->twig = $twig; $this->twig = $twig;
} }

View File

@ -38,16 +38,16 @@ class LintCommand extends Command
*/ */
public function __construct($twig = null) public function __construct($twig = null)
{ {
parent::__construct();
if (!$twig instanceof Environment) { if (!$twig instanceof Environment) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $twig ? 'lint:twig' : $twig); parent::__construct($twig);
return; return;
} }
parent::__construct();
$this->twig = $twig; $this->twig = $twig;
} }

View File

@ -42,16 +42,16 @@ class AssetsInstallCommand extends ContainerAwareCommand
*/ */
public function __construct($filesystem = null) public function __construct($filesystem = null)
{ {
parent::__construct();
if (!$filesystem instanceof Filesystem) { if (!$filesystem instanceof Filesystem) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $filesystem ? 'assets:install' : $filesystem); parent::__construct($filesystem);
return; return;
} }
parent::__construct();
$this->filesystem = $filesystem; $this->filesystem = $filesystem;
} }

View File

@ -39,16 +39,16 @@ class CacheClearCommand extends ContainerAwareCommand
*/ */
public function __construct($cacheClearer = null, Filesystem $filesystem = null) public function __construct($cacheClearer = null, Filesystem $filesystem = null)
{ {
parent::__construct();
if (!$cacheClearer instanceof CacheClearerInterface) { if (!$cacheClearer instanceof CacheClearerInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $cacheClearer ? 'cache:clear' : $cacheClearer); parent::__construct($cacheClearer);
return; return;
} }
parent::__construct();
$this->cacheClearer = $cacheClearer; $this->cacheClearer = $cacheClearer;
$this->filesystem = $filesystem ?: new Filesystem(); $this->filesystem = $filesystem ?: new Filesystem();
} }

View File

@ -32,16 +32,16 @@ final class CachePoolClearCommand extends ContainerAwareCommand
*/ */
public function __construct($poolClearer = null) public function __construct($poolClearer = null)
{ {
parent::__construct();
if (!$poolClearer instanceof Psr6CacheClearer) { if (!$poolClearer instanceof Psr6CacheClearer) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $poolClearer ? 'cache:pool:clear' : $poolClearer); parent::__construct($poolClearer);
return; return;
} }
parent::__construct();
$this->poolClearer = $poolClearer; $this->poolClearer = $poolClearer;
} }

View File

@ -33,16 +33,16 @@ class CacheWarmupCommand extends ContainerAwareCommand
*/ */
public function __construct($cacheWarmer = null) public function __construct($cacheWarmer = null)
{ {
parent::__construct();
if (!$cacheWarmer instanceof CacheWarmerAggregate) { if (!$cacheWarmer instanceof CacheWarmerAggregate) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $cacheWarmer ? 'cache:warmup' : $cacheWarmer); parent::__construct($cacheWarmer);
return; return;
} }
parent::__construct();
$this->cacheWarmer = $cacheWarmer; $this->cacheWarmer = $cacheWarmer;
} }

View File

@ -35,16 +35,16 @@ class EventDispatcherDebugCommand extends ContainerAwareCommand
*/ */
public function __construct($dispatcher = null) public function __construct($dispatcher = null)
{ {
parent::__construct();
if (!$dispatcher instanceof EventDispatcherInterface) { if (!$dispatcher instanceof EventDispatcherInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $dispatcher ? 'debug:event-dispatcher' : $dispatcher); parent::__construct($dispatcher);
return; return;
} }
parent::__construct();
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
} }

View File

@ -39,16 +39,16 @@ class RouterDebugCommand extends ContainerAwareCommand
*/ */
public function __construct($router = null) public function __construct($router = null)
{ {
parent::__construct();
if (!$router instanceof RouterInterface) { if (!$router instanceof RouterInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $router ? 'debug:router' : $router); parent::__construct($router);
return; return;
} }
parent::__construct();
$this->router = $router; $this->router = $router;
} }

View File

@ -36,16 +36,16 @@ class RouterMatchCommand extends ContainerAwareCommand
*/ */
public function __construct($router = null) public function __construct($router = null)
{ {
parent::__construct();
if (!$router instanceof RouterInterface) { if (!$router instanceof RouterInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $router ? 'router:match' : $router); parent::__construct($router);
return; return;
} }
parent::__construct();
$this->router = $router; $this->router = $router;
} }

View File

@ -36,14 +36,14 @@ use Symfony\Component\Translation\TranslatorInterface;
*/ */
class TranslationDebugCommand extends ContainerAwareCommand class TranslationDebugCommand extends ContainerAwareCommand
{ {
private $translator;
private $loader;
private $extractor;
const MESSAGE_MISSING = 0; const MESSAGE_MISSING = 0;
const MESSAGE_UNUSED = 1; const MESSAGE_UNUSED = 1;
const MESSAGE_EQUALS_FALLBACK = 2; const MESSAGE_EQUALS_FALLBACK = 2;
private $translator;
private $loader;
private $extractor;
/** /**
* @param TranslatorInterface $translator * @param TranslatorInterface $translator
* @param TranslationLoader $loader * @param TranslationLoader $loader
@ -51,16 +51,16 @@ class TranslationDebugCommand extends ContainerAwareCommand
*/ */
public function __construct($translator = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null) public function __construct($translator = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null)
{ {
parent::__construct();
if (!$translator instanceof TranslatorInterface) { if (!$translator instanceof TranslatorInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $translator ? 'debug:translation' : $translator); parent::__construct($translator);
return; return;
} }
parent::__construct();
$this->translator = $translator; $this->translator = $translator;
$this->loader = $loader; $this->loader = $loader;
$this->extractor = $extractor; $this->extractor = $extractor;

View File

@ -46,16 +46,16 @@ class TranslationUpdateCommand extends ContainerAwareCommand
*/ */
public function __construct($writer = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null, $defaultLocale = null) public function __construct($writer = null, TranslationLoader $loader = null, ExtractorInterface $extractor = null, $defaultLocale = null)
{ {
parent::__construct();
if (!$writer instanceof TranslationWriter) { if (!$writer instanceof TranslationWriter) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED); @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
$this->setName(null === $writer ? 'translation:update' : $writer); parent::__construct($writer);
return; return;
} }
parent::__construct();
$this->writer = $writer; $this->writer = $writer;
$this->loader = $loader; $this->loader = $loader;
$this->extractor = $extractor; $this->extractor = $extractor;

View File

@ -11,9 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Command; namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand; use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand;
/** /**
@ -25,39 +22,41 @@ use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand;
* *
* @final since version 3.4 * @final since version 3.4
*/ */
class XliffLintCommand extends Command class XliffLintCommand extends BaseLintCommand
{ {
private $command; public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
{
if (func_num_args()) {
@trigger_error(sprintf('Passing a constructor argument in "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
}
if (null === $directoryIteratorProvider) {
$directoryIteratorProvider = function ($directory, $default) {
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return $default($directory);
};
}
if (null === $isReadableProvider) {
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
};
}
parent::__construct($name, $directoryIteratorProvider, $isReadableProvider);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function configure() protected function configure()
{ {
$this->setName('lint:xliff'); parent::configure();
if (!$this->isEnabled()) { $this->setHelp($this->getHelp().<<<'EOF'
return;
}
$directoryIteratorProvider = function ($directory, $default) {
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return $default($directory);
};
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
};
$this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider);
$this
->setDescription($this->command->getDescription())
->setDefinition($this->command->getDefinition())
->setHelp($this->command->getHelp().<<<'EOF'
Or find all files in a bundle: Or find all files in a bundle:
@ -66,17 +65,4 @@ Or find all files in a bundle:
EOF EOF
); );
} }
/**
* {@inheritdoc}
*/
public function isEnabled()
{
return class_exists(BaseLintCommand::class);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->command->execute($input, $output);
}
} }

View File

@ -11,9 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Command; namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand; use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
/** /**
@ -24,39 +21,41 @@ use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
* *
* @final since version 3.4 * @final since version 3.4
*/ */
class YamlLintCommand extends Command class YamlLintCommand extends BaseLintCommand
{ {
private $command; public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
{
if (func_num_args()) {
@trigger_error(sprintf('Passing a constructor argument in "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
}
if (null === $directoryIteratorProvider) {
$directoryIteratorProvider = function ($directory, $default) {
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return $default($directory);
};
}
if (null === $isReadableProvider) {
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
};
}
parent::__construct($name, $directoryIteratorProvider, $isReadableProvider);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function configure() protected function configure()
{ {
$this->setName('lint:yaml'); parent::configure();
if (!$this->isEnabled()) { $this->setHelp($this->getHelp().<<<'EOF'
return;
}
$directoryIteratorProvider = function ($directory, $default) {
if (!is_dir($directory)) {
$directory = $this->getApplication()->getKernel()->locateResource($directory);
}
return $default($directory);
};
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
};
$this->command = new BaseLintCommand(null, $directoryIteratorProvider, $isReadableProvider);
$this
->setDescription($this->command->getDescription())
->setDefinition($this->command->getDefinition())
->setHelp($this->command->getHelp().<<<'EOF'
Or find all files in a bundle: Or find all files in a bundle:
@ -65,17 +64,4 @@ Or find all files in a bundle:
EOF EOF
); );
} }
/**
* {@inheritdoc}
*/
public function isEnabled()
{
return class_exists(BaseLintCommand::class) && parent::isEnabled();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->command->execute($input, $output);
}
} }

View File

@ -18,6 +18,8 @@ use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand; use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand; use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand;
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand; use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
use Symfony\Bundle\FrameworkBundle\Command\XliffLintCommand;
use Symfony\Bundle\FrameworkBundle\Command\YamlLintCommand;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader; use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
@ -69,10 +71,12 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\WebLink\HttpHeaderSerializer; use Symfony\Component\WebLink\HttpHeaderSerializer;
use Symfony\Component\Workflow; use Symfony\Component\Workflow;
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
/** /**
* FrameworkExtension. * FrameworkExtension.
@ -128,6 +132,13 @@ class FrameworkExtension extends Extension
if (class_exists(Application::class)) { if (class_exists(Application::class)) {
$loader->load('console.xml'); $loader->load('console.xml');
if (!class_exists(BaseXliffLintCommand::class)) {
$container->removeDefinition(XliffLintCommand::class);
}
if (!class_exists(BaseYamlLintCommand::class)) {
$container->removeDefinition(YamlLintCommand::class);
}
} }
// Property access is used by both the Form and the Validator component // Property access is used by both the Form and the Validator component

View File

@ -14,6 +14,8 @@ namespace Symfony\Bundle\SecurityBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\SchemaException;
/** /**
@ -25,12 +27,37 @@ use Doctrine\DBAL\Schema\SchemaException;
*/ */
class InitAclCommand extends ContainerAwareCommand class InitAclCommand extends ContainerAwareCommand
{ {
private $connection;
private $schema;
/**
* @param Connection $connection
* @param Schema $schema
*/
public function __construct($connection = null, Schema $schema = null)
{
if (!$connection instanceof Connection) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
parent::__construct($connection);
return;
}
parent::__construct();
$this->connection = $connection;
$this->schema = $schema;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* BC to be removed in 4.0
*/ */
public function isEnabled() public function isEnabled()
{ {
if (!$this->getContainer()->has('security.acl.dbal.connection')) { if (!$this->connection && !$this->getContainer()->has('security.acl.dbal.connection')) {
return false; return false;
} }
@ -65,21 +92,22 @@ EOF
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$container = $this->getContainer(); // BC to be removed in 4.0
if (null === $this->connection) {
$connection = $container->get('security.acl.dbal.connection'); $this->connection = $this->getContainer()->get('security.acl.dbal.connection');
$schema = $container->get('security.acl.dbal.schema'); $this->schema = $this->getContainer()->get('security.acl.dbal.schema');
}
try { try {
$schema->addToSchema($connection->getSchemaManager()->createSchema()); $this->schema->addToSchema($this->connection->getSchemaManager()->createSchema());
} catch (SchemaException $e) { } catch (SchemaException $e) {
$output->writeln('Aborting: '.$e->getMessage()); $output->writeln('Aborting: '.$e->getMessage());
return 1; return 1;
} }
foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { foreach ($this->schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$connection->exec($sql); $this->connection->exec($sql);
} }
$output->writeln('ACL tables have been initialized successfully.'); $output->writeln('ACL tables have been initialized successfully.');

View File

@ -32,11 +32,36 @@ use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface;
*/ */
class SetAclCommand extends ContainerAwareCommand class SetAclCommand extends ContainerAwareCommand
{ {
private $provider;
/**
* @param MutableAclProviderInterface $provider
*/
public function __construct($provider = null)
{
if (!$provider instanceof MutableAclProviderInterface) {
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version 3.4 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
parent::__construct($provider);
return;
}
parent::__construct();
$this->provider = $provider;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* BC to be removed in 4.0
*/ */
public function isEnabled() public function isEnabled()
{ {
if (null !== $this->provider) {
return parent::isEnabled();
}
if (!$this->getContainer()->has('security.acl.provider')) { if (!$this->getContainer()->has('security.acl.provider')) {
return false; return false;
} }
@ -91,6 +116,11 @@ EOF
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
// BC to be removed in 4.0
if (null === $this->provider) {
$this->provider = $this->getContainer()->get('security.acl.provider');
}
// Parse arguments // Parse arguments
$objectIdentities = array(); $objectIdentities = array();
$maskBuilder = $this->getMaskBuilder(); $maskBuilder = $this->getMaskBuilder();
@ -136,20 +166,15 @@ EOF
} }
} }
/** @var $container \Symfony\Component\DependencyInjection\ContainerInterface */
$container = $this->getContainer();
/** @var $aclProvider MutableAclProviderInterface */
$aclProvider = $container->get('security.acl.provider');
// Sets ACL // Sets ACL
foreach ($objectIdentities as $objectIdentity) { foreach ($objectIdentities as $objectIdentity) {
// Creates a new ACL if it does not already exist // Creates a new ACL if it does not already exist
try { try {
$aclProvider->createAcl($objectIdentity); $this->provider->createAcl($objectIdentity);
} catch (AclAlreadyExistsException $e) { } catch (AclAlreadyExistsException $e) {
} }
$acl = $aclProvider->findAcl($objectIdentity, $securityIdentities); $acl = $this->provider->findAcl($objectIdentity, $securityIdentities);
foreach ($securityIdentities as $securityIdentity) { foreach ($securityIdentities as $securityIdentity) {
if ($classScopeOption) { if ($classScopeOption) {
@ -159,13 +184,15 @@ EOF
} }
} }
$aclProvider->updateAcl($acl); $this->provider->updateAcl($acl);
} }
} }
/** /**
* Gets the mask builder. * Gets the mask builder.
* *
* BC to be removed in 4.0
*
* @return MaskBuilder * @return MaskBuilder
*/ */
protected function getMaskBuilder() protected function getMaskBuilder()

View File

@ -11,6 +11,8 @@
namespace Symfony\Bundle\SecurityBundle\DependencyInjection; namespace Symfony\Bundle\SecurityBundle\DependencyInjection;
use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
use Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand; use Symfony\Bundle\SecurityBundle\Command\UserPasswordEncoderCommand;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
@ -114,6 +116,9 @@ class SecurityExtension extends Extension
// load ACL // load ACL
if (isset($config['acl'])) { if (isset($config['acl'])) {
$this->aclLoad($config['acl'], $container); $this->aclLoad($config['acl'], $container);
} else {
$container->removeDefinition(InitAclCommand::class);
$container->removeDefinition(SetAclCommand::class);
} }
$container->registerForAutoconfiguration(VoterInterface::class) $container->registerForAutoconfiguration(VoterInterface::class)

View File

@ -8,10 +8,13 @@
<defaults public="false" /> <defaults public="false" />
<service id="Symfony\Bundle\SecurityBundle\Command\InitAclCommand"> <service id="Symfony\Bundle\SecurityBundle\Command\InitAclCommand">
<argument type="service" id="security.acl.dbal.connection" />
<argument type="service" id="security.acl.dbal.schema" />
<tag name="console.command" command="init:acl" /> <tag name="console.command" command="init:acl" />
</service> </service>
<service id="Symfony\Bundle\SecurityBundle\Command\SetAclCommand"> <service id="Symfony\Bundle\SecurityBundle\Command\SetAclCommand">
<argument type="service" id="security.acl.provider" />
<tag name="console.command" command="acl:set" /> <tag name="console.command" command="acl:set" />
</service> </service>

View File

@ -96,7 +96,7 @@ class SetAclCommandTest extends WebTestCase
$role = 'ROLE_ADMIN'; $role = 'ROLE_ADMIN';
$application = $this->getApplication(); $application = $this->getApplication();
$application->add(new SetAclCommand()); $application->add(new SetAclCommand($application->getKernel()->getContainer()->get('security.acl.provider')));
$setAclCommand = $application->find('acl:set'); $setAclCommand = $application->find('acl:set');
$setAclCommandTester = new CommandTester($setAclCommand); $setAclCommandTester = new CommandTester($setAclCommand);
@ -138,7 +138,7 @@ class SetAclCommandTest extends WebTestCase
$role = 'ROLE_USER'; $role = 'ROLE_USER';
$application = $this->getApplication(); $application = $this->getApplication();
$application->add(new SetAclCommand()); $application->add(new SetAclCommand($application->getKernel()->getContainer()->get('security.acl.provider')));
$setAclCommand = $application->find('acl:set'); $setAclCommand = $application->find('acl:set');
$setAclCommandTester = new CommandTester($setAclCommand); $setAclCommandTester = new CommandTester($setAclCommand);
@ -170,7 +170,7 @@ class SetAclCommandTest extends WebTestCase
$kernel->boot(); $kernel->boot();
$application = new Application($kernel); $application = new Application($kernel);
$application->add(new InitAclCommand()); $application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));
$initAclCommand = $application->find('init:acl'); $initAclCommand = $application->find('init:acl');
$initAclCommandTester = new CommandTester($initAclCommand); $initAclCommandTester = new CommandTester($initAclCommand);