-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Commands as a service #23624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
da49f81
48228aa
76097b3
bc90a30
9b0a5a4
d99e0b9
a404323
d0b35d0
2067d8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,17 +26,34 @@ | |
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Gábor Egyed <gabor.egyed@gmail.com> | ||
* | ||
* @final since version 3.4 | ||
*/ | ||
class AssetsInstallCommand extends ContainerAwareCommand | ||
{ | ||
const METHOD_COPY = 'copy'; | ||
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink'; | ||
const METHOD_RELATIVE_SYMLINK = 'relative symlink'; | ||
|
||
private $filesystem; | ||
|
||
/** | ||
* @var Filesystem | ||
* @param Filesystem $filesystem | ||
*/ | ||
private $filesystem; | ||
public function __construct($filesystem = null) | ||
{ | ||
parent::__construct(); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. message is confusing if I was not passing anything as argument |
||
|
||
$this->setName(null === $filesystem ? 'assets:install' : $filesystem); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm you're right.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks |
||
|
||
return; | ||
} | ||
|
||
$this->filesystem = $filesystem; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
|
@@ -79,10 +96,17 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
// BC to be removed in 4.0 | ||
if (null === $this->filesystem) { | ||
$this->filesystem = $this->getContainer()->get('filesystem'); | ||
$baseDir = $this->getContainer()->getParameter('kernel.project_dir'); | ||
} | ||
|
||
$kernel = $this->getApplication()->getKernel(); | ||
$targetArg = rtrim($input->getArgument('target'), '/'); | ||
|
||
if (!is_dir($targetArg)) { | ||
$targetArg = $this->getContainer()->getParameter('kernel.project_dir').'/'.$targetArg; | ||
$targetArg = (isset($baseDir) ? $baseDir : $kernel->getContainer()->getParameter('kernel.project_dir')).'/'.$targetArg; | ||
|
||
if (!is_dir($targetArg)) { | ||
// deprecated, logic to be removed in 4.0 | ||
|
@@ -95,8 +119,6 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
} | ||
|
||
$this->filesystem = $this->getContainer()->get('filesystem'); | ||
|
||
// Create the bundles directory otherwise symlink will fail. | ||
$bundlesDir = $targetArg.'/bundles/'; | ||
$this->filesystem->mkdir($bundlesDir, 0777); | ||
|
@@ -122,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$exitCode = 0; | ||
$validAssetDirs = array(); | ||
/** @var BundleInterface $bundle */ | ||
foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { | ||
foreach ($kernel->getBundles() as $bundle) { | ||
if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) { | ||
continue; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,26 @@ | |
*/ | ||
final class CachePoolClearCommand extends ContainerAwareCommand | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed... I should have reviewed more carefully 😊 |
||
{ | ||
private $poolClearer; | ||
|
||
/** | ||
* @param Psr6CacheClearer $poolClearer | ||
*/ | ||
public function __construct($poolClearer = null) | ||
{ | ||
parent::__construct(); | ||
|
||
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); | ||
|
||
$this->setName(null === $poolClearer ? 'cache:pool:clear' : $poolClearer); | ||
|
||
return; | ||
} | ||
|
||
$this->poolClearer = $poolClearer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -50,18 +70,22 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
// BC to be removed in 4.0 | ||
if (null === $this->poolClearer) { | ||
$this->poolClearer = $this->getContainer()->get('cache.global_clearer'); | ||
$cacheDir = $this->getContainer()->getParameter('kernel.cache_dir'); | ||
} | ||
|
||
$io = new SymfonyStyle($input, $output); | ||
$kernel = $this->getApplication()->getKernel(); | ||
$pools = array(); | ||
$clearers = array(); | ||
$container = $this->getContainer(); | ||
$cacheDir = $container->getParameter('kernel.cache_dir'); | ||
$globalClearer = $container->get('cache.global_clearer'); | ||
|
||
foreach ($input->getArgument('pools') as $id) { | ||
if ($globalClearer->hasPool($id)) { | ||
if ($this->poolClearer->hasPool($id)) { | ||
$pools[$id] = $id; | ||
} else { | ||
$pool = $container->get($id); | ||
$pool = $kernel->getContainer()->get($id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it won't be containeraware in 4.0, but this will still be supported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it was just to be consistent with the code above but that's fine for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We basically favor kernel aware over container aware. See also #23632 We might favor kernel injection over kernel aware. That would be the most flexible, but not sure if needed. |
||
|
||
if ($pool instanceof CacheItemPoolInterface) { | ||
$pools[$id] = $pool; | ||
|
@@ -75,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
foreach ($clearers as $id => $clearer) { | ||
$io->comment(sprintf('Calling cache clearer: <info>%s</info>', $id)); | ||
$clearer->clear($cacheDir); | ||
$clearer->clear(isset($cacheDir) ? $cacheDir : $kernel->getContainer()->getParameter('kernel.cache_dir')); | ||
} | ||
|
||
foreach ($pools as $id => $pool) { | ||
|
@@ -84,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
if ($pool instanceof CacheItemPoolInterface) { | ||
$pool->clear(); | ||
} else { | ||
$globalClearer->clearPool($id); | ||
$this->poolClearer->clearPool($id); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh...
null
implies new api?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
has never been an allowed name so LGTM as isUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it is.. https://github.com/symfony/symfony/blob/v3.3.6/src/Symfony/Component/Console/Command/Command.php#L51
leaning to make filesystem a required dep..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine for me