8000 [Lock] Replaced method injection in AddConsoleCommandPass to register… · symfony/symfony@c05870e · GitHub
[go: up one dir, main page]

Skip to content

Commit c05870e

Browse files
author
Jelle van Oosterbosch
committed
[Lock] Replaced method injection in AddConsoleCommandPass to registerForAutoConfiguration
Added LockableInterface as marker
1 parent 2669abf commit c05870e

File tree

5 files changed

+16
-43
lines changed

5 files changed

+16
-43
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
7070
use Symfony\Component\Lock\Factory;
7171
use Symfony\Component\Lock\Lock;
72+
use Symfony\Component\Lock\LockableInterface;
7273
use Symfony\Component\Lock\LockInterface;
7374
use Symfony\Component\Lock\Store\FlockStore;
7475
use Symfony\Component\Lock\Store\StoreFactory;
@@ -419,6 +420,8 @@ public function load(array $configs, ContainerBuilder $container)
419420
->addTag('mime.mime_type_guesser');
420421
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
421422
->addMethodCall('setLogger', [new Reference('logger')]);
423+
$container->registerForAutoconfiguration(LockableInterface::class)
424+
->addMethodCall('setStore', [new Reference('lock.default.store')]);
422425

423426
if (!$container->getParameter('kernel.debug')) {
424427
// remove tagged iterator argument for resource checkers

src/Symfony/Component/Console/Command/LockableTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ private function release()
8181

8282
/**
8383
* Sets the internal store for the command to be used.
84-
*
85-
* @param StoreInterface $store
8684
*/
8785
public function setStore(StoreInterface $store)
8886
{

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ public function process(ContainerBuilder $container)
8686
if ($aliases) {
8787
$definition->addMethodCall('setAliases', [$aliases]);
8888
}
89-
90-
$storeDefinition = 'lock.default.store';
91-
if ($container->hasDefinition($storeDefinition)) {
92-
if (\method_exists($definition->getClass(), 'setStore')) {
93-
$definition->addMethodCall('setStore', [$container->getDefinition($storeDefinition)]);
94-
}
95-
}
9689
}
9790

9891
$container

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Command\Command;
16-
use Symfony\Component\Console\Command\LockableTrait;
1716
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
1817
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
1918
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -247,34 +246,6 @@ public function testProcessOnChildDefinitionWithoutClass()
247246

248247
$container->compile();
249248
}
250-
251-
public function testProcessRegistersStoreInCommand()
252-
{
253-
$storeClassName = 'Symfony\Component\Lock\StoreInterface';
254-
255-
$container = new ContainerBuilder();
256-
$container
257-
->register('lock.default.store', $this->createMock($storeClassName))
258-
->setPublic(false)
259-
;
260-
$container
261-
->register('lockable.command', LockableCommand::class)
262-
->setPublic(false)
263-
->addTag('console.command', ['command' => 'lockable'])
264-
;
265-
266-
$pass = new AddConsoleCommandPass();
267-
$pass->process($container);
268-
269-
$command = $container->get('lockable.command');
270-
$this->assertInstanceOf(LockableCommand::class, $command);
271-
272-
$reflection = new \ReflectionClass($command);
273-
$property = $reflection->getProperty('store');
274-
$property->setAccessible(true);
275-
$store = $property->getValue($command);
276-
$this->assertInstanceOf($storeClassName, $store);
277-
}
278249
}
279250

280251
class MyCommand extends Command
@@ -285,8 +256,3 @@ class NamedCommand extends Command
285256
{
286257
protected static $defaultName = 'default';
287258
}
288-
289-
class LockableCommand extends Command
290-
{
291-
use LockableTrait;
292-
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Lock;
4+
5+
interface LockableInterface
6+
{
7+
/**
8+
* Sets the current store.
9+
*
10+
* @param StoreInterface $store The store to be used
11+
*/
12+
public function setStore(StoreInterface $store);
13+
}

0 commit comments

Comments
 (0)
0