-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.php
96 lines (80 loc) · 2.38 KB
/
Command.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php declare(strict_types=1);
/*
* This file is part of the Rapsys AirBundle package.
*
* (c) Raphaël Gertz <symfony@rapsys.eu>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Rapsys\AirBundle;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Rapsys\AirBundle\RapsysAirBundle;
use Rapsys\PackBundle\Util\SluggerUtil;
/**
* {@inheritdoc}
*/
class Command extends BaseCommand {
/**
* {@inheritdoc}
*
* Creates new command
*
* @param ManagerRegistry $doctrine The doctrine instance
* @param RouterInterface $router The router instance
* @param SluggerUtil $slugger The slugger instance
* @param TranslatorInterface $translator The translator instance
* @param string $locale The default locale
*/
public function __construct(protected ManagerRegistry $doctrine, protected string $locale, protected RouterInterface $router, protected SluggerUtil $slugger, protected TranslatorInterface $translator, protected ?string $name = null) {
//Fix name
$this->name = $this->name ?? static::getName();
//Call parent constructor
parent::__construct($this->name);
//With description
if (!empty($this->description)) {
//Set description
$this->setDescription($this->description);
}
//With help
if (!empty($this->help)) {
//Set help
$this->setHelp($this->help);
}
//Get router context
$context = $this->router->getContext();
//Set hostname
$context->setHost($_ENV['RAPSYSAIR_HOSTNAME']);
//Set scheme
$context->setScheme($_ENV['RAPSYSAIR_SCHEME'] ?? 'https');
}
/**
* {@inheritdoc}
*
* Return the command name
*/
public function getName(): string {
//With namespace
if ($npos = strrpos(static::class, '\\')) {
//Set name pos
$npos++;
//Without namespace
} else {
$npos = 0;
}
//With trailing command
if (substr(static::class, -strlen('Command'), strlen('Command')) === 'Command') {
//Set bundle pos
$bpos = strlen(static::class) - $npos - strlen('Command');
//Without bundle
} else {
//Set bundle pos
$bpos = strlen(static::class) - $npos;
}
//Return command alias
return RapsysAirBundle::getAlias().':'.strtolower(substr(static::class, $npos, $bpos));
}
}