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