[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Console/ -> ExtensionDiscoverCommand.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Console;
  11  
  12  use Joomla\Console\Command\AbstractCommand;
  13  use Symfony\Component\Console\Command\Command;
  14  use Symfony\Component\Console\Input\InputInterface;
  15  use Symfony\Component\Console\Output\OutputInterface;
  16  use Symfony\Component\Console\Style\SymfonyStyle;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('JPATH_PLATFORM') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Console command for discovering extensions
  24   *
  25   * @since  4.0.0
  26   */
  27  class ExtensionDiscoverCommand extends AbstractCommand
  28  {
  29      /**
  30       * The default command name
  31       *
  32       * @var    string
  33       *
  34       * @since  4.0.0
  35       */
  36      protected static $defaultName = 'extension:discover';
  37  
  38      /**
  39       * Stores the Input Object
  40       *
  41       * @var    InputInterface
  42       *
  43       * @since  4.0.0
  44       */
  45      private $cliInput;
  46  
  47      /**
  48       * SymfonyStyle Object
  49       *
  50       * @var    SymfonyStyle
  51       *
  52       * @since  4.0.0
  53       */
  54      private $ioStyle;
  55  
  56      /**
  57       * Configures the IO
  58       *
  59       * @param   InputInterface   $input   Console Input
  60       * @param   OutputInterface  $output  Console Output
  61       *
  62       * @return  void
  63       *
  64       * @since   4.0.0
  65       *
  66       */
  67      private function configureIO(InputInterface $input, OutputInterface $output): void
  68      {
  69          $this->cliInput = $input;
  70          $this->ioStyle = new SymfonyStyle($input, $output);
  71      }
  72  
  73      /**
  74       * Initialise the command.
  75       *
  76       * @return  void
  77       *
  78       * @since   4.0.0
  79       */
  80      protected function configure(): void
  81      {
  82          $help = "<info>%command.name%</info> is used to discover extensions
  83          \nUsage:
  84          \n  <info>php %command.full_name%</info>";
  85  
  86          $this->setDescription('Discover extensions');
  87          $this->setHelp($help);
  88      }
  89  
  90      /**
  91       * Used for discovering extensions
  92       *
  93       * @return  integer  The count of discovered extensions
  94       *
  95       * @throws  \Exception
  96       *
  97       * @since   4.0.0
  98       */
  99      public function processDiscover(): int
 100      {
 101          $app = $this->getApplication();
 102  
 103          $mvcFactory = $app->bootComponent('com_installer')->getMVCFactory();
 104  
 105          $model = $mvcFactory->createModel('Discover', 'Administrator');
 106  
 107          return $model->discover();
 108      }
 109  
 110      /**
 111       * Used for finding the text for the note
 112       *
 113       * @param   int  $count   The count of installed Extensions
 114       *
 115       * @return  string  The text for the note
 116       *
 117       * @since   4.0.0
 118       */
 119      public function getNote(int $count): string
 120      {
 121          if ($count < 1) {
 122              return 'No extensions were discovered.';
 123          } elseif ($count === 1) {
 124              return $count . ' extension has been discovered.';
 125          } else {
 126              return $count . ' extensions have been discovered.';
 127          }
 128      }
 129  
 130      /**
 131       * Internal function to execute the command.
 132       *
 133       * @param   InputInterface   $input   The input to inject into the command.
 134       * @param   OutputInterface  $output  The output to inject into the command.
 135       *
 136       * @return  integer  The command exit code
 137       *
 138       * @since   4.0.0
 139       */
 140      protected function doExecute(InputInterface $input, OutputInterface $output): int
 141      {
 142          $this->configureIO($input, $output);
 143  
 144          $count = $this->processDiscover();
 145          $this->ioStyle->title('Discover Extensions');
 146          $this->ioStyle->note($this->getNote($count));
 147  
 148          return Command::SUCCESS;
 149      }
 150  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer