]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command.php
Replace dropped site.title with title.site
[airbundle] / Command.php
index 6f4a8eeb6f6e68f2cd425b1aa1597e04c1a94d05..c775499fab5747269334d4ffc4a42968741b8693 100644 (file)
@@ -9,9 +9,10 @@
  * file that was distributed with this source code.
  */
 
  * file that was distributed with this source code.
  */
 
-namespace Rapsys\AirBundle\Command;
+namespace Rapsys\AirBundle;
 
 use Doctrine\Persistence\ManagerRegistry;
 
 use Doctrine\Persistence\ManagerRegistry;
+
 use Symfony\Component\Console\Command\Command as BaseCommand;
 use Symfony\Component\Routing\RouterInterface;
 use Symfony\Contracts\Translation\TranslatorInterface;
 use Symfony\Component\Console\Command\Command as BaseCommand;
 use Symfony\Component\Routing\RouterInterface;
 use Symfony\Contracts\Translation\TranslatorInterface;
@@ -20,43 +21,13 @@ use Rapsys\AirBundle\RapsysAirBundle;
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
+/**
+ * {@inheritdoc}
+ */
 class Command extends BaseCommand {
        /**
 class Command extends BaseCommand {
        /**
-        * Doctrine instance
-        *
-        * @var ManagerRegistry
-        */
-       protected ManagerRegistry $doctrine;
-
-       /**
-        * Router instance
-        *
-        * @var RouterInterface
-        */
-       protected RouterInterface $router;
-
-       /**
-        * Slugger instance
-        *
-        * @var SluggerUtil
-        */
-       protected SluggerUtil $slugger;
-
-       /**
-        * Translator instance
-        *
-        * @var TranslatorInterface
-        */
-       protected TranslatorInterface $translator;
-
-       /**
-        * Locale
+        * {@inheritdoc}
         *
         *
-        * @var string
-        */
-       protected string $locale;
-
-       /**
         * Creates new command
         *
         * @param ManagerRegistry $doctrine The doctrine instance
         * Creates new command
         *
         * @param ManagerRegistry $doctrine The doctrine instance
@@ -65,52 +36,61 @@ class Command extends BaseCommand {
         * @param TranslatorInterface $translator The translator instance
         * @param string $locale The default locale
         */
         * @param TranslatorInterface $translator The translator instance
         * @param string $locale The default locale
         */
-       public function __construct(ManagerRegistry $doctrine, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator, string $locale) {
-               //Call parent constructor
-               parent::__construct();
+       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();
 
 
-               //Set doctrine
-               $this->doctrine = $doctrine;
+               //Call parent constructor
+               parent::__construct($this->name);
 
 
-               //Set router
-               $this->router = $router;
+               //With description
+               if (!empty($this->description)) {
+                       //Set description
+                       $this->setDescription($this->description);
+               }
 
 
-               //Set slugger
-               $this->slugger = $slugger;
+               //With help
+               if (!empty($this->help)) {
+                       //Set help
+                       $this->setHelp($this->help);
+               }
 
                //Get router context
                $context = $this->router->getContext();
 
 
                //Get router context
                $context = $this->router->getContext();
 
-               //Set host
-               $context->setHost('airlibre.eu');
+               //Set hostname
+               $context->setHost($_ENV['RAPSYSAIR_HOSTNAME']);
 
                //Set scheme
 
                //Set scheme
-               $context->setScheme('https');
-
-               //Set the translator
-               $this->translator = $translator;
-
-               //Set locale
-               $this->locale = $locale;
-
-               //With default name
-               //TODO: XXX: see how to make it works
-               /*if (isset(self::$defaultName)) {
-                       $this->name = self::$defaultName;
-               }
-
-               //With default description
-               if (isset(self::$defaultDescription)) {
-                       $this->name = self::$defaultDescription;
-               }*/
+               $context->setScheme($_ENV['RAPSYSAIR_SCHEME'] ?? 'https');
        }
 
        /**
        }
 
        /**
-        * Return the bundle alias
-        *
         * {@inheritdoc}
         * {@inheritdoc}
+        *
+        * Return the command name
         */
         */
-       public function getAlias(): string {
-               return RapsysAirBundle::getAlias();
+       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));
        }
 }
        }
 }