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 b8f29f1

Browse filesBrowse files
committed
[Framework] cleaned up command registration magic
1 parent 5fa4b0b commit b8f29f1
Copy full SHA for b8f29f1

File tree

Expand file treeCollapse file tree

1 file changed

+12
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-19
lines changed

‎src/Symfony/Framework/Bundle/Bundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Framework/Bundle/Bundle.php
+12-19Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Components\DependencyInjection\ContainerInterface;
66
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
77
use Symfony\Components\Console\Application;
8+
use Symfony\Components\Finder\Finder;
89

910
/*
1011
* This file is part of the Symfony framework.
@@ -115,32 +116,24 @@ public function getReflection()
115116
}
116117

117118
/**
118-
* Registers the Commands for the console.
119+
* Finds and registers commands for the current bundle.
119120
*
120121
* @param Symfony\Components\Console\Application $application An Application instance
121122
*/
122123
public function registerCommands(Application $application)
123124
{
124-
foreach ($application->getKernel()->getBundleDirs() as $dir) {
125-
$bundleBase = dirname(str_replace('\\', '/', get_class($this)));
126-
$commandDir = $dir.'/'.basename($bundleBase).'/Command';
127-
if (!is_dir($commandDir)) {
128-
continue;
129-
}
130-
131-
// look for commands
132-
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($commandDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
133-
if ($file->isDir() || substr($file, -4) !== '.php') {
134-
continue;
135-
}
136-
137-
$class = str_replace('/', '\\', $bundleBase).'\\Command\\'.str_replace(realpath($commandDir).'/', '', basename(realpath($file), '.php'));
125+
if (!is_dir($dir = $this->getPath().'/Command')) {
126+
return;
127+
}
138128

139-
$r = new \ReflectionClass($class);
129+
$finder = new Finder();
130+
$finder->files()->name('*Command.php')->in($dir);
140131

141-
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
142-
$application->addCommand(new $class());
143-
}
132+
$prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command\\';
133+
foreach ($finder as $file) {
134+
$r = new \ReflectionClass($prefix.basename($file, '.php'));
135+
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
136+
$application->addCommand($r->newInstance());
144137
}
145138
}
146139
}

0 commit comments

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