8000 added missing support for factories in console descriptions by fabpot · Pull Request #13307 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

added missing support for factories in console descriptions #13307

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

Merged
merged 1 commit into from
Jan 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
16 changes: 16 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
Expand Down Expand Up @@ -231,6 +232,21 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
$data['factory_method'] = $definition->getFactoryMethod();
}

if ($factory = $definition->getFactory()) {
if (is_array($factory)) {
if ($factory[0] instanceof Reference) {
$data['factory_service'] = (string) $factory[0];
} elseif ($factory[0] instanceof Definition) {
throw new \InvalidArgumentException('Factory is not describable.');
} else {
$data['factory_class'] = $factory[0];
}
$data['factory_method'] = $factory[1];
} else {
$data['factory_function'] = $factory;
}
}

if (!$omitTags) {
$data['tags'] = array();
if (count($definition->getTags())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
Expand Down Expand Up @@ -201,6 +202,21 @@ protected function describeContainerDefinition(Definition $definition, array $op
$output .= "\n".'- Factory Method: `'.$definition->getFactoryMethod().'`';
}

if ($factory = $definition->getFactory()) {
if (is_array($factory)) {
if ($factory[0] instanceof Reference) {
$output .= "\n".'- Factory Service: `'.$factory[0].'`';
} elseif ($factory[0] instanceof Definition) {
throw new \InvalidArgumentException('Factory is not describable.');
} else {
$output .= "\n".'- Factory Class: `'.$factory[0].'`';
}
$output .= "\n".'- Factory Method: `'.$factory[1].'`';
} else {
$output .= "\n".'- Factory Function: `'.$factory.'`';
}
}

if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
foreach ($definition->getTags() as $tagName => $tagData) {
foreach ($tagData as $parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
Expand Down Expand Up @@ -283,6 +284,21 @@ protected function describeContainerDefinition(Definition $definition, array $op
$description[] = sprintf('<comment>Factory Method</comment> %s', $definition->getFactoryMethod());
}

if ($factory = $definition->getFactory()) {
if (is_array($factory)) {
if ($factory[0] instanceof Reference) {
$description[] = sprintf('<comment>Factory Service</comment> %s', $factory[0]);
} elseif ($factory[0] instanceof Definition) {
throw new \InvalidArgumentException('Factory is not describable.');
} else {
$description[] = sprintf('<comment>Factory Class</comment> %s', $factory[0]);
}
$description[] = sprintf('<comment>Factory Method</comment> %s', $factory[1]);
} else {
$description[] = sprintf('<comment>Factory Function</comment> %s', $factory);
}
}

$this->writeText(implode("\n", $description)."\n", $options);
}

Expand Down
0