-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
SimpleSutCommands.php
56 lines (50 loc) · 1.92 KB
/
SimpleSutCommands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Drush\Commands;
use Consolidation\AnnotatedCommand\AnnotationData;
use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareTrait;
use Consolidation\Log\ConsoleLogLevel;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drush\Drush;
use Drush\Symfony\DrushArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Drush\Commands\DrushCommands;
use Drush\Style\DrushStyle;
use Drush\Utils\StringUtils;
/**
* Site-wide commands for the System-Under-Test site
*/
class SimpleSutCommands extends DrushCommands
{
/**
* Show a message.
*
* @command sut:simple
* @hidden
*/
public function example()
{
$this->logger()->notice(dt("This is an example site-wide command committed to the repository in the SUT inside of the 'drush/Commands' directory."));
}
/**
* Replace Drush logger with a custom one.
*
* In a real-world implementation, you would likely use `@hook *` instead of `@hook sut:simple`.
*
* @hook init sut:simple
*/
public function customLogger(DrushArgvInput $argv, AnnotationData $annotationData): void
{
$verbosityLevelMap = [ConsoleLogLevel::SUCCESS => OutputInterface::VERBOSITY_NORMAL];
$formatLevelMap = [ConsoleLogLevel::SUCCESS => \Psr\Log\LogLevel::INFO];
// One could use Monolog if desired.
// Drush expects custom loggers to always write to stderr, so dont use ConsoleLogger directly,
$newLogger = new ConsoleLogger(Drush::output(), $verbosityLevelMap, $formatLevelMap);
$drushLoggerManager = $this->logger();
$drushLoggerManager->reset()->add('foo', $newLogger);
}
}