Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e25239

Browse filesBrowse files
committed
Remove symfony/symfony BC layers from console commands
1 parent 95ee777 commit 3e25239
Copy full SHA for 3e25239

File tree

Expand file treeCollapse file tree

3 files changed

+13
-151
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+13
-151
lines changed

‎Command/InitAclCommand.php

Copy file name to clipboardExpand all lines: Command/InitAclCommand.php
+5-45Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\AclBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
1717
use Symfony\Component\Security\Acl\Dbal\Schema;
@@ -25,53 +25,27 @@
2525
*
2626
* @final since version 3.4
2727
*/
28-
class InitAclCommand extends ContainerAwareCommand
28+
class InitAclCommand extends Command
2929
{
30+
protected static $defaultName = 'acl:init';
31+
3032
private $connection;
3133
private $schema;
3234

33-
/**
34-
* @param Connection $connection
35-
* @param Schema $schema
36-
*/
37-
public function __construct($connection = null, Schema $schema = null)
35+
public function __construct(Connection $connection, Schema $schema)
3836
{
39-
if (!$connection instanceof Connection) {
40-
@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);
41-
42-
parent::__construct($connection);
43-
44-
return;
45-
}
46-
4737
parent::__construct();
4838

4939
$this->connection = $connection;
5040
$this->schema = $schema;
5141
}
5242

53-
/**
54-
* {@inheritdoc}
55-
*
56-
* BC to be removed in 4.0
57-
*/
58-
public function isEnabled()
59-
{
60-
if (!$this->connection && !$this->getContainer()->has('security.acl.dbal.connection')) {
61-
return false;
62-
}
63-
64-
return parent::isEnabled();
65-
}
66-
6743
/**
6844
* {@inheritdoc}
6945
*/
7046
protected function configure()
7147
{
7248
$this
73-
->setName('acl:init')
74-
->setAliases(array('init:acl'))
7549
->setDescription('Mounts ACL tables in the database')
7650
->setHelp(<<<'EOF'
7751
The <info>%command.name%</info> command mounts ACL tables in the database.
@@ -93,20 +67,6 @@ protected function configure()
9367
*/
9468
protected function execute(InputInterface $input, OutputInterface $output)
9569
{
96-
if (false !== strpos($input->getFirstArgument(), ':a')) {
97-
$warning = 'The use of "init:acl" command is deprecated since version 3.4 and will be removed in 4.0. Use the "acl:init" command instead.';
98-
99-
@trigger_error($warning, E_USER_DEPRECATED);
100-
101-
$output->writeln('<comment>'.$warning.'</>');
102-
}
103-
104-
// BC to be removed in 4.0
105-
if (null === $this->connection) {
106-
$this->connection = $this->getContainer()->get('security.acl.dbal.connection');
107-
$this->schema = $this->getContainer()->get('security.acl.dbal.schema');
108-
}
109-
11070
try {
11171
$this->schema->addToSchema($this->connection->getSchemaManager()->createSchema());
11272
} catch (SchemaException $e) {

‎Command/SetAclCommand.php

Copy file name to clipboardExpand all lines: Command/SetAclCommand.php
+8-58Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Symfony\Bundle\AclBundle\Command;
1313

14-
15-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use Symfony\Component\Console\Command\Command;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
1817
use Symfony\Component\Console\Input\InputOption;
@@ -31,61 +30,29 @@
3130
*
3231
* @final since version 3.4
3332
*/
34-
class SetAclCommand extends ContainerAwareCommand
33+
class SetAclCommand extends Command
3534
{
35+
protected static $defaultName = 'acl:set';
36+
3637
private $provider;
3738

38-
/**
39-
* @param MutableAclProviderInterface $provider
40-
*/
41-
public function __construct($provider = null)
39+
public function __construct(MutableAclProviderInterface $provider)
4240
{
43-
if (!$provider instanceof MutableAclProviderInterface) {
44-
@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);
45-
46-
parent::__construct($provider);
47-
48-
return;
49-
}
50-
5141
parent::__construct();
5242

5343
$this->provider = $provider;
5444
}
5545

56-
/**
57-
* {@inheritdoc}
58-
*
59-
* BC to be removed in 4.0
60-
*/
61-
public function isEnabled()
62-
{
63-
if (null !== $this->provider) {
64-
return parent::isEnabled();
65-
}
66-
if (!$this->getContainer()->has('security.acl.provider')) {
67-
return false;
68-
}
69-
70-
$provider = $this->getContainer()->get('security.acl.provider');
71-
if (!$provider instanceof MutableAclProviderInterface) {
72-
return false;
73-
}
74-
75-
return parent::isEnabled();
76-
}
77-
7846
/**
7947
* {@inheritdoc}
8048
*/
8149
protected function configure()
8250
{
8351
$this
84-
->setName('acl:set')
8552
->setDescription('Sets ACL for objects')
8653
->setHelp(<<<EOF
8754
The <info>%command.name%</info> command sets ACL.
88-
The ACL system must have been initialized with the <info>acl:init</info> command.
55+
The ACL system must have been initialized with the <info>init:acl</info> command.
8956
9057
To set <comment>VIEW</comment> and <comment>EDIT</comment> permissions for the user <comment>kevin</comment> on the instance of
9158
<comment>Acme\MyClass</comment> having the identifier <comment>42</comment>:
@@ -117,14 +84,9 @@ protected function configure()
11784
*/
11885
protected function execute(InputInterface $input, OutputInterface $output)
11986
{
120-
// BC to be removed in 4.0
121-
if (null === $this->provider) {
122-
$this->provider = $this->getContainer()->get('security.acl.provider');
123-
}
124-
12587
// Parse arguments
12688
$objectIdentities = array();
127-
$maskBuilder = $this->getMaskBuilder();
89+
$maskBuilder = new MaskBuilder();
12890
foreach ($input->getArgument('arguments') as $argument) {
12991
$data = explode(':', $argument, 2);
13092

@@ -153,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
153115
foreach ($userOption as $user) {
154116
$data = explode(':', $user, 2);
155117

156-
if (count($data) === 1) {
118+
if (1 === count($data)) {
157119
throw new \InvalidArgumentException('The user must follow the format "Acme/MyUser:username".');
158120
}
159121

@@ -188,16 +150,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
188150
$this->provider->updateAcl($acl);
189151
}
190152
}
191-
192-
/**
193-
* Gets the mask builder.
194-
*
195-
* BC to be removed in 4.0
196-
*
197-
* @return MaskBuilder
198-
*/
199-
protected function getMaskBuilder()
200-
{
201-
return new MaskBuilder();
202-
}
203153
}

‎Tests/Functional/SetAclCommandTest.php

Copy file name to clipboardExpand all lines: Tests/Functional/SetAclCommandTest.php
-48Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,6 @@ class SetAclCommandTest extends KernelTestCase
3434
const OBJECT_CLASS = 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AclBundle\Entity\Car';
3535
const SECURITY_CLASS = User::class;
3636

37-
/**
38-
* @group legacy
39-
*/
40-
public function testSetAclUser()
41-
{
42-
$objectId = 1;
43-
$securityUsername1 = 'kevin';
44-
$securityUsername2 = 'anne';
45-
$grantedPermission1 = 'VIEW';
46-
$grantedPermission2 = 'EDIT';
47-
48-
$application = $this->getApplication();
49-
$application->add(new SetAclCommand());
50-
51-
$setAclCommand = $application->find('acl:set');
52-
$setAclCommandTester = new CommandTester($setAclCommand);
53-
$setAclCommandTester->execute(array(
54-
'command' => 'acl:set',
55-
'arguments' => array($grantedPermission1, $grantedPermission2, sprintf('%s:%s', self::OBJECT_CLASS, $objectId)),
56-
'--user' => array(sprintf('%s:%s', self::SECURITY_CLASS, $securityUsername1), sprintf('%s:%s', self::SECURITY_CLASS, $securityUsername2)),
57-
));
58-
59-
$objectIdentity = new ObjectIdentity($objectId, self::OBJECT_CLASS);
60-
$securityIdentity1 = new UserSecurityIdentity($securityUsername1, self::SECURITY_CLASS);
61-
$securityIdentity2 = new UserSecurityIdentity($securityUsername2, self::SECURITY_CLASS);
62-
$permissionMap = new BasicPermissionMap();
63-
64-
/** @var \Symfony\Component\Security\Acl\Model\AclProviderInterface $aclProvider */
65-
$aclProvider = $application->getKernel()->getContainer()->get('security.acl.provider');
66-
$acl = $aclProvider->findAcl($objectIdentity, array($securityIdentity1));
67-
68-
$this->assertTrue($acl->isGranted($permissionMap->getMasks($grantedPermission1, null), array($securityIdentity1)));
69-
$this->assertTrue($acl->isGranted($permissionMap->getMasks($grantedPermission1, null), array($securityIdentity2)));
70-
$this->assertTrue($acl->isGranted($permissionMap->getMasks($grantedPermission2, null), array($securityIdentity2)));
71-
72-
try {
73-
$acl->isGranted($permissionMap->getMasks('OWNER', null), array($securityIdentity1));
74-
$this->fail('NoAceFoundException not throwed');
75-
} catch (NoAceFoundException $e) {
76-
}
77-
78-
try {
79-
$acl->isGranted($permissionMap->getMasks('OPERATOR', null), array($securityIdentity2));
80-
$this->fail('NoAceFoundException not throwed');
81-
} catch (NoAceFoundException $e) {
82-
}
83-
}
84-
8537
public function testSetAclRole()
8638
{
8739
$objectId = 1;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.