Skip to content
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

Add logger channel generation for generate:service command #3841

Merged
merged 2 commits into from
Apr 10, 2019
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
18 changes: 18 additions & 0 deletions src/Command/Generate/ServiceCommand.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 %}