[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Console/ -> ExtensionDiscoverListCommand.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 Symfony\Component\Console\Command\Command;
  13  use Symfony\Component\Console\Input\InputInterface;
  14  use Symfony\Component\Console\Output\OutputInterface;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Console command for list discovered extensions
  22   *
  23   * @since  4.0.0
  24   */
  25  class ExtensionDiscoverListCommand extends ExtensionsListCommand
  26  {
  27      /**
  28       * The default command name
  29       *
  30       * @var    string
  31       *
  32       * @since  4.0.0
  33       */
  34      protected static $defaultName = 'extension:discover:list';
  35  
  36      /**
  37       * Initialise the command.
  38       *
  39       * @return  void
  40       *
  41       * @since   4.0.0
  42       */
  43      protected function configure(): void
  44      {
  45          $help = "<info>%command.name%</info> is used to list all extensions that could be installed via discoverinstall
  46          \nUsage:
  47          \n  <info>php %command.full_name%</info>";
  48  
  49          $this->setDescription('List discovered extensions');
  50          $this->setHelp($help);
  51      }
  52  
  53      /**
  54       * Filters the extension state
  55       *
  56       * @param   array   $extensions  The Extensions
  57       * @param   string  $state       The Extension state
  58       *
  59       * @return array
  60       *
  61       * @since 4.0.0
  62       */
  63      public function filterExtensionsBasedOnState($extensions, $state): array
  64      {
  65          $filteredExtensions = [];
  66  
  67          foreach ($extensions as $key => $extension) {
  68              if ($extension['state'] === $state) {
  69                  $filteredExtensions[] = $extension;
  70              }
  71          }
  72  
  73          return $filteredExtensions;
  74      }
  75  
  76      /**
  77       * Internal function to execute the command.
  78       *
  79       * @param   InputInterface   $input   The input to inject into the command.
  80       * @param   OutputInterface  $output  The output to inject into the command.
  81       *
  82       * @return  integer  The command exit code
  83       *
  84       * @since   4.0.0
  85       */
  86      protected function doExecute(InputInterface $input, OutputInterface $output): int
  87      {
  88          $this->configureIO($input, $output);
  89          $this->ioStyle->title('Discovered Extensions');
  90  
  91          $extensions = $this->getExtensions();
  92          $state = -1;
  93  
  94          $discovered_extensions = $this->filterExtensionsBasedOnState($extensions, $state);
  95  
  96          if (empty($discovered_extensions)) {
  97              $this->ioStyle->note("There are no pending discovered extensions to install. Perhaps you need to run extension:discover first?");
  98  
  99              return Command::SUCCESS;
 100          }
 101  
 102          $discovered_extensions = $this->getExtensionsNameAndId($discovered_extensions);
 103  
 104          $this->ioStyle->table(['Name', 'Extension ID', 'Version', 'Type', 'Enabled'], $discovered_extensions);
 105  
 106          return Command::SUCCESS;
 107      }
 108  }


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