‪TYPO3CMS  9.5
SiteListCommand.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Symfony\Component\Console\Command\Command;
20 use Symfony\Component\Console\Helper\Table;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
23 use Symfony\Component\Console\Style\SymfonyStyle;
25 
29 class ‪SiteListCommand extends Command
30 {
34  protected function ‪configure()
35  {
36  $this->setDescription('Shows the list of sites available to the system.');
37  }
38 
44  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
45  {
46  $io = new SymfonyStyle($input, ‪$output);
47  $siteFinder = new ‪SiteFinder();
48  $sites = $siteFinder->getAllSites();
49 
50  if (empty($sites)) {
51  $io->title('No sites configured');
52  $io->note('Configure new sites in the "Sites" module.');
53  return 0;
54  }
55 
56  $io->title('All configured sites');
57  $table = new Table(‪$output);
58  $table->setHeaders([
59  'Identifier',
60  'Root PID',
61  'Base URL',
62  'Language',
63  'Locale',
64  'Status',
65  ]);
66  foreach ($sites as $site) {
67  $baseUrls = [];
68  $languages = [];
69  ‪$locales = [];
70  $status = [];
71  foreach ($site->getLanguages() as $language) {
72  $baseUrls[] = (string)$language->getBase();
73  $languages[] = sprintf(
74  '%s (id:%d)',
75  $language->getTitle(),
76  $language->getLanguageId()
77  );
78  ‪$locales[] = $language->getLocale();
79  $status[] = $language->isEnabled()
80  ? '<fg=green>enabled</>'
81  : '<fg=yellow>disabled</>';
82  }
83  $table->addRow(
84  [
85  '<options=bold>' . $site->getIdentifier() . '</>',
86  $site->getRootPageId(),
87  implode("\n", $baseUrls),
88  implode("\n", $languages),
89  implode("\n", ‪$locales),
90  implode("\n", $status),
91  ]
92  );
93  }
94  $table->render();
95  return 0;
96  }
97 }
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪$locales
‪$locales
Definition: be_users.php:6
‪TYPO3\CMS\Core\Command\SiteListCommand
Definition: SiteListCommand.php:30
‪TYPO3\CMS\Core\Command\SiteListCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SiteListCommand.php:44
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Core\Command
Definition: DumpAutoloadCommand.php:3
‪TYPO3\CMS\Core\Command\SiteListCommand\configure
‪configure()
Definition: SiteListCommand.php:34