Skip to content

Commit

Permalink
Add logger channel generation for generate:service command (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
LOBsTerr committed Apr 10, 2019
1 parent 75f5784 commit d80825f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Command/Generate/ServiceCommand.php
Expand Up @@ -120,6 +120,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.service.options.interface-name')
)
->addOption(
'logger-channel',
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.service.options.logger-channel')
)
->addOption(
'services',
null,
Expand Down Expand Up @@ -150,6 +156,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$class = $this->validator->validateClassName($input->getOption('class'));
$interface = $input->getOption('interface');
$interface_name = $input->getOption('interface-name');
$logger_channel = $input->getOption('logger-channel');
$services = $input->getOption('services');
$path_service = $input->getOption('path-service');

Expand All @@ -172,6 +179,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'class' => $class,
'interface' => $interface,
'interface_name' => $interface_name,
'logger_channel' => $logger_channel,
'services' => $build_services,
'path_service' => $path_service,
]);
Expand Down Expand Up @@ -231,6 +239,16 @@ function ($class) {
$input->setOption('interface-name', $interface_name);
}

// --logger-channel option
$logger_channel = $input->getOption('logger-channel');
if (!$logger_channel) {
$logger_channel = $this->getIo()->confirm(
$this->trans('commands.generate.service.questions.logger-channel'),
true
);
$input->setOption('logger-channel', $logger_channel);
}

// --services option
$services = $input->getOption('services');
if (!$services) {
Expand Down
8 changes: 7 additions & 1 deletion templates/module/services.yml.twig
@@ -1,7 +1,12 @@
{% if name is defined %}
{% if not file_exists %}
services:
{% endif %}
{% if logger_channel is defined %}
logger.channel.{{ module }}:
parent: logger.channel_base
arguments: ['{{ module }}']
{% endif %}
{% if name is defined %}
{{ name | lower }}:
class: {{ class_path }}
{% if services is defined %}
Expand All @@ -11,4 +16,5 @@ services:
tags:
- { {{ tagsAsArray(tags)|join(', ') }} }
{% endif %}

{% endif %}

0 comments on commit d80825f

Please sign in to comment.