Skip to content

Commit d209a4e

Browse files
javiereguiluzfabpot
authored andcommitted
Updated the styles of the container commands
1 parent bee1faa commit d209a4e

18 files changed

+255
-182
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2021
use Symfony\Component\DependencyInjection\ContainerBuilder;
2122
use Symfony\Component\Config\FileLocator;
22-
use Symfony\Component\Console\Question\ChoiceQuestion;
2323

2424
/**
2525
* A console command for retrieving information about services.
@@ -94,8 +94,9 @@ protected function configure()
9494
*/
9595
protected function execute(InputInterface $input, OutputInterface $output)
9696
{
97+
$output = new SymfonyStyle($input, $output);
9798
if (false !== strpos($input->getFirstArgument(), ':d')) {
98-
$output->writeln('<comment>The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.</comment>');
99+
$output->caution('The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.');
99100
}
100101

101102
$this->validateInput($input);
@@ -124,10 +125,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
124125
$helper = new DescriptorHelper();
125126
$options['format'] = $input->getOption('format');
126127
$options['raw_text'] = $input->getOption('raw');
128+
$options['output'] = $output;
127129
$helper->describe($output, $object, $options);
128130

129131
if (!$input->getArgument('name') && $input->isInteractive()) {
130-
$output->writeln('To search for a service, re-run this command with a search term. <comment>debug:container log</comment>');
132+
$output->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
131133
}
132134
}
133135

@@ -186,7 +188,7 @@ protected function getContainerBuilder()
186188
return $this->containerBuilder = $container;
187189
}
188190

189-
private function findProperServiceName(InputInterface $input, OutputInterface $output, ContainerBuilder $builder, $name)
191+
private function findProperServiceName(InputInterface $input, SymfonyStyle $output, ContainerBuilder $builder, $name)
190192
{
191193
if ($builder->has($name) || !$input->isInteractive()) {
192194
return $name;
@@ -197,10 +199,7 @@ private function findProperServiceName(InputInterface $input, OutputInterface $o
197199
throw new \InvalidArgumentException(sprintf('No services found that match "%s".', $name));
198200
}
199201

200-
$question = new ChoiceQuestion('Choose a number for more information on the service', $matchingServices);
201-
$question->setErrorMessage('Service %s is invalid.');
202-
203-
return $this->getHelper('question')->ask($input, $output, $question);
202+
return $output->choice('Select one of the following services to display its information', $matchingServices);
204203
}
205204

206205
private function findServiceIdsContaining(ContainerBuilder $builder, $name)

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

Lines changed: 95 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,15 @@ protected function describeRoute(Route $route, array $options = array())
105105
*/
106106
protected function describeContainerParameters(ParameterBag $parameters, array $options = array())
107107
{
108-
$table = new Table($this->getOutput());
109-
$table->setStyle('compact');
110-
$table->setHeaders(array('Parameter', 'Value'));
108+
$tableHeaders = array('Parameter', 'Value');
111109

110+
$tableRows = array();
112111
foreach ($this->sortParameters($parameters) as $parameter => $value) {
113-
$table->addRow(array($parameter, $this->formatParameter($value)));
112+
$tableRows[] = array($parameter, $this->formatParameter($value));
114113
}
115114

116-
$this->writeText($this->formatSection('container', 'List of parameters')."\n", $options);
117-
$table->render();
115+
$options['output']->title('Symfony Container Parameters');
116+
$options['output']->table($tableHeaders, $tableRows);
118117
}
119118

120119
/**
@@ -123,15 +122,17 @@ protected function describeContainerParameters(ParameterBag $parameters, array $
123122
protected function describeContainerTags(ContainerBuilder $builder, array $options = array())
124123
{
125124
$showPrivate = isset($options['show_private']) && $options['show_private'];
126-
$description = array($this->formatSection('container', 'Tagged services'));
127125

128-
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
129-
$description[] = $this->formatSection('tag', $tag);
130-
$description = array_merge($description, array_keys($definitions));
131-
$description[] = '';
126+
if ($showPrivate) {
127+
$options['output']->title('Symfony Container Public and Private Tags');
128+
} else {
129+
$options['output']->title('Symfony Container Public Tags');
132130
}
133131

134-
$this->writeText(implode("\n", $description), $options);
132+
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
133+
$options['output']->section(sprintf('"%s" tag', $tag));
134+
$options['output']->listing(array_keys($definitions));
135+
}
135136
}
136137

137138
/**
@@ -148,11 +149,13 @@ protected function describeContainerService($service, array $options = array())
148149
} elseif ($service instanceof Definition) {
149150
$this->describeContainerDefinition($service, $options);
150151
} else {
151-
$description = $this->formatSection('container', sprintf('Information for service <info>%s</info>', $options['id']))
152-
."\n".sprintf('<comment>Service Id</comment> %s', isset($options['id']) ? $options['id'] : '-')
153-
."\n".sprintf('<comment>Class</comment> %s', get_class($service));
154-
155-
$this->writeText($description, $options);
152+
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
153+
$options['output']->table(
154+
array('Service ID', 'Class'),
155+
array(
156+
array(isset($options['id']) ? $options['id'] : '-', get_class($service)),
157+
)
158+
);
156159
}
157160
}
158161

@@ -165,16 +168,16 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
165168
$showTag = isset($options['tag']) ? $options['tag'] : null;
166169

167170
if ($showPrivate) {
168-
$label = '<comment>Public</comment> and <comment>private</comment> services';
171+
$title = 'Symfony Container Public and Private Services';
169172
} else {
170-
$label = '<comment>Public</comment> services';
173+
$title = 'Symfony Container Public Services';
171174
}
172175

173176
if ($showTag) {
174-
$label .= ' with tag <info>'.$options['tag'].'</info>';
177+
$title .= sprintf(' Tagged with "%s" Tag', $options['tag']);
175178
}
176179

177-
$this->writeText($this->formatSection('container', $label)."\n", $options);
180+
$options['output']->title($title);
178181

179182
$serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
180183
$maxTags = array();
@@ -206,10 +209,8 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
206209
$tagsCount = count($maxTags);
207210
$tagsNames = array_keys($maxTags);
208211

209-
$table = new Table($this->getOutput());
210-
$table->setStyle('compact');
211-
$table->setHeaders(array_merge(array('Service ID'), $tagsNames, array('Class name')));
212-
212+
$tableHeaders = array_merge(array('Service ID'), $tagsNames, array('Class name'));
213+
$tableRows = array();
213214
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
214215
$definition = $this->resolveServiceDefinition($builder, $serviceId);
215216
if ($definition instanceof Definition) {
@@ -220,112 +221,125 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
220221
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : '';
221222
}
222223
if (0 === $key) {
223-
$table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass())));
224+
$tableRows[] = array_merge(array($serviceId), $tagValues, array($definition->getClass()));
224225
} else {
225-
$table->addRow(array_merge(array(' "'), $tagValues, array('')));
226+
$tableRows[] = array_merge(array(' "'), $tagValues, array(''));
226227
}
227228
}
228229
} else {
229-
$table->addRow(array($serviceId, $definition->getClass()));
230+
$tableRows[] = array($serviceId, $definition->getClass());
230231
}
231232
} elseif ($definition instanceof Alias) {
232233
$alias = $definition;
233-
$table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, '') : array()));
234+
$tableRows[] = array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, '') : array());
234235
} else {
235236
// we have no information (happens with "service_container")
236-
$table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, '') : array()));
237+
$tableRows[] = array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, '') : array());
237238
}
238239
}
239240

240-
$table->render();
241+
$options['output']->table($tableHeaders, $tableRows);
241242
}
242243

243244
/**
244245
* {@inheritdoc}
245246
*/
246247
protected function describeContainerDefinition(Definition $definition, array $options = array())
247248
{
248-
$description = isset($options['id'])
249-
? array($this->formatSection('container', sprintf('Information for service <info>%s</info>', $options['id'])))
250-
: array();
249+
if (isset($options['id'])) {
250+
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
251+
}
251252

252-
$description[] = sprintf('<comment>Service Id</comment> %s', isset($options['id']) ? $options['id'] : '-');
253-
$description[] = sprintf('<comment>Class</comment> %s', $definition->getClass() ?: '-');
253+
$tableHeaders = array('Option', 'Value');
254+
255+
$tableRows[] = array('Service ID', isset($options['id']) ? $options['id'] : '-');
256+
$tableRows[] = array('Class', $definition->getClass() ?: '-');
254257

255258
$tags = $definition->getTags();
256259
if (count($tags)) {
257-
$description[] = '<comment>Tags</comment>';
260+
$tagInformation = '';
258261
foreach ($tags as $tagName => $tagData) {
259-
foreach ($tagData as $parameters) {
260-
$description[] = sprintf(' - %-30s (%s)', $tagName, implode(', ', array_map(function ($key, $value) {
262+
foreach ($tagData as $tagParameters) {
263+
$parameters = array_map(function ($key, $value) {
261264
return sprintf('<info>%s</info>: %s', $key, $value);
262-
}, array_keys($parameters), array_values($parameters))));
265+
}, array_keys($tagParameters), array_values($tagParameters));
266+
$parameters = implode(', ', $parameters);
267+
268+
if ('' === $parameters) {
269+
$tagInformation .= sprintf('%s', $tagName);
270+
} else {
271+
$tagInformation .= sprintf('%s (%s)', $tagName, $parameters);
272+
}
263273
}
264274
}
265275
} else {
266-
$description[] = '<comment>Tags</comment> -';
276+
$tagInformation = '-';
267277
}
278+
$tableRows[] = array('Tags', $tagInformation);
279+
280+
$tableRows[] = array('Scope', $definition->getScope(false));
281+
$tableRows[] = array('Public', $definition->isPublic() ? 'yes' : 'no');
282+
$tableRows[] = array('Synthetic', $definition->isSynthetic() ? 'yes' : 'no');
283+
$tableRows[] = array('Lazy', $definition->isLazy() ? 'yes' : 'no');
268284

269-
$description[] = sprintf('<comment>Scope</comment> %s', $definition->getScope(false));
270-
$description[] = sprintf('<comment>Public</comment> %s', $definition->isPublic() ? 'yes' : 'no');
271-
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
272-
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
273-
if (method_exists($definition, 'isShared')) {
274-
$description[] = sprintf('<comment>Shared</comment> %s', $definition->isShared() ? 'yes' : 'no');
275-
}
276285
if (method_exists($definition, 'isSynchronized')) {
277-
$description[] = sprintf('<comment>Synchronized</comment> %s', $definition->isSynchronized(false) ? 'yes' : 'no');
286+
$tableRows[] = array('Synchronized', $definition->isSynchronized(false) ? 'yes' : 'no');
278287
}
279-
$description[] = sprintf('<comment>Abstract</comment> %s', $definition->isAbstract() ? 'yes' : 'no');
288+
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
280289

281290
if ($definition->getFile()) {
282-
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ?: '-');
291+
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');
283292
}
284293

285294
if ($definition->getFactoryClass(false)) {
286-
$description[] = sprintf('<comment>Factory Class</comment> %s', $definition->getFactoryClass(false));
295+
$tableRows[] = array('Factory Class', $definition->getFactoryClass(false));
287296
}
288297

289298
if ($definition->getFactoryService(false)) {
290-
$description[] = sprintf('<comment>Factory Service</comment> %s', $definition->getFactoryService(false));
299+
$tableRows[] = array('Factory Service', $definition->getFactoryService(false));
291300
}
292301

293302
if ($definition->getFactoryMethod(false)) {
294-
$description[] = sprintf('<comment>Factory Method</comment> %s', $definition->getFactoryMethod(false));
303+
$tableRows[] = array('Factory Method', $definition->getFactoryMethod(false));
295304
}
296305

297306
if ($factory = $definition->getFactory()) {
298307
if (is_array($factory)) {
299308
if ($factory[0] instanceof Reference) {
300-
$description[] = sprintf('<comment>Factory Service</comment> %s', $factory[0]);
309+
$tableRows[] = array('Factory Service', $factory[0]);
301310
} elseif ($factory[0] instanceof Definition) {
302311
throw new \InvalidArgumentException('Factory is not describable.');
303312
} else {
304-
$description[] = sprintf('<comment>Factory Class</comment> %s', $factory[0]);
313+
$tableRows[] = array('Factory Class', $factory[0]);
305314
}
306-
$description[] = sprintf('<comment>Factory Method</comment> %s', $factory[1]);
315+
$tableRows[] = array('Factory Method', $factory[1]);
307316
} else {
308-
$description[] = sprintf('<comment>Factory Function</comment> %s', $factory);
317+
$tableRows[] = array('Factory Function', $factory);
309318
}
310319
}
311320

312-
$this->writeText(implode("\n", $description)."\n", $options);
321+
$options['output']->table($tableHeaders, $tableRows);
313322
}
314323

315324
/**
316325
* {@inheritdoc}
317326
*/
318327
protected function describeContainerAlias(Alias $alias, array $options = array())
319328
{
320-
$this->writeText(sprintf("This service is an alias for the service <info>%s</info>\n", (string) $alias), $options);
329+
$options['output']->comment(sprintf("This service is an alias for the service <info>%s</info>\n", (string) $alias));
321330
}
322331

323332
/**
324333
* {@inheritdoc}
325334
*/
326335
protected function describeContainerParameter($parameter, array $options = array())
327336
{
328-
$this->writeText($this->formatParameter($parameter), $options);
337+
$options['output']->table(
338+
array('Parameter', 'Value'),
339+
array(
340+
array($options['parameter'], $this->formatParameter($parameter),
341+
),
342+
));
329343
}
330344

331345
/**
@@ -344,16 +358,33 @@ protected function describeEventDispatcherListeners(EventDispatcherInterface $ev
344358

345359
$this->writeText($this->formatSection('event_dispatcher', $label)."\n", $options);
346360

347-
$registeredListeners = $eventDispatcher->getListeners($event, true);
361+
$registeredListeners = $eventDispatcher->getListeners($event);
348362

349363
if (null !== $event) {
350364
$this->writeText("\n");
351-
$this->renderEventListenerTable($registeredListeners);
365+
$table = new Table($this->getOutput());
366+
$table->getStyle()->setCellHeaderFormat('%s');
367+
$table->setHeaders(array('Order', 'Callable'));
368+
369+
foreach ($registeredListeners as $order => $listener) {
370+
$table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($listener)));
371+
}
372+
373+
$table->render();
352374
} else {
353375
ksort($registeredListeners);
354376
foreach ($registeredListeners as $eventListened => $eventListeners) {
355377
$this->writeText(sprintf("\n<info>[Event]</info> %s\n", $eventListened), $options);
356-
$this->renderEventListenerTable($eventListeners);
378+
379+
$table = new Table($this->getOutput());
380+
$table->getStyle()->setCellHeaderFormat('%s');
381+
$table->setHeaders(array('Order', 'Callable'));
382+
383+
foreach ($eventListeners as $order => $eventListener) {
384+
$table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($eventListener)));
385+
}
386+
387+
$table->render();
357388
}
358389
}
359390
}

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

14+
use Symfony\Component\Console\Input\ArrayInput;
1415
use Symfony\Component\Console\Output\BufferedOutput;
16+
use Symfony\Component\Console\Style\SymfonyStyle;
1517
use Symfony\Component\DependencyInjection\Alias;
1618
use Symfony\Component\DependencyInjection\ContainerBuilder;
1719
use Symfony\Component\DependencyInjection\Definition;
@@ -149,6 +151,11 @@ private function assertDescription($expectedDescription, $describedObject, array
149151
{
150152
$options['raw_output'] = true;
151153
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
154+
155+
if ('txt' === $this->getFormat()) {
156+
$options['output'] = new SymfonyStyle(new ArrayInput(array()), $output);
157+
}
158+
152159
$this->getDescriptor()->describe($output, $describedObject, $options);
153160

154161
if ('json' === $this->getFormat()) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This service is an alias for the service <info>service_1</info>
1+
// This service is an alias for the service service_1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This service is an alias for the service <info>service_2</info>
1+
// This service is an alias for the service service_2

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy