8000 bug #13307 added missing support for factories in console description… · symfony/symfony@8d982f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d982f8

Browse files
committed
bug #13307 added missing support for factories in console descriptions (fabpot)
This PR was merged into the 2.6 branch. Discussion ---------- added missing support for factories in console descriptions | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Follow-up for #13305 Commits ------- f7fcefa added missing support for factories in console descriptions
2 parents 4308bd8 + f7fcefa commit 8d982f8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Definition;
2121
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
22+
use Symfony\Component\DependencyInjection\Reference;
2223
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2324
use Symfony\Component\Routing\Route;
2425
use Symfony\Component\Routing\RouteCollection;
@@ -231,6 +232,21 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
231232
$data['factory_method'] = $definition->getFactoryMethod();
232233
}
233234

235+
if ($factory = $definition->getFactory()) {
236+
if (is_array($factory)) {
237+
if ($factory[0] instanceof Reference) {
238+
$data['factory_service'] = (string) $factory[0];
239+
} elseif ($factory[0] instanceof Definition) {
240+
throw new \InvalidArgumentException('Factory is not describable.');
241+
} else {
242+
$data['factory_class'] = $factory[0];
243+
}
244+
$data['factory_method'] = $factory[1];
245+
} else {
246+
$data['factory_function'] = $factory;
247+
}
248+
}
249+
234250
if (!$omitTags) {
235251
$data['tags'] = array();
236252
if (count($definition->getTags())) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
18+
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Routing\RouteCollection;
@@ -201,6 +202,21 @@ protected function describeContainerDefinition(Definition $definition, array $op
201202
$output .= "\n".'- Factory Method: `'.$definition->getFactoryMethod().'`';
202203
}
203204

205+
if ($factory = $definition->getFactory()) {
206+
if (is_array($factory)) {
207+
if ($factory[0] instanceof Reference) {
208+
$output .= "\n".'- Factory Service: `'.$factory[0].'`';
209+
} elseif ($factory[0] instanceof Definition) {
210+
throw new \InvalidArgumentException('Factory is not describable.');
211+
} else {
212+
$output .= "\n".'- Factory Class: `'.$factory[0].'`';
213+
}
214+
$output .= "\n".'- Factory Method: `'.$factory[1].'`';
215+
} else {
216+
$output .= "\n".'- Factory Function: `'.$factory.'`';
217+
}
218+
}
219+
204220
if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
205221
foreach ($definition->getTags() as $tagName => $tagData) {
206222
foreach ($tagData as $parameters) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
19+
use Symfony\Component\DependencyInjection\Reference;
1920
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2021
use Symfony\Component\Routing\Route;
2122
use Symfony\Component\Routing\RouteCollection;
@@ -283,6 +284,21 @@ protected function describeContainerDefinition(Definition $definition, array $op
283284
$description[] = sprintf('<comment>Factory Method</comment> %s', $definition->getFactoryMethod());
284285
}
285286

287+
if ($factory = $definition->getFactory()) {
288+
if (is_array($factory)) {
289+
if ($factory[0] instanceof Reference) {
290+
$description[] = sprintf('<comment>Factory Service</comment> %s', $factory[0]);
291+
} elseif ($factory[0] instanceof Definition) {
292+
throw new \InvalidArgumentException('Factory is not describable.');
293+
} else {
294+
$description[] = sprintf('<comment>Factory Class</comment> %s', $factory[0]);
295+
}
296+
$description[] = sprintf('<comment>Factory Method</comment> %s', $factory[1]);
297+
} else {
298+
$description[] = sprintf('<comment>Factory Function</comment> %s', $factory);
299+
}
300+
}
301+
286302
$this->writeText(implode("\n", $description)."\n", $options);
287303
}
288304

0 commit comments

Comments
 (0)
0