‪TYPO3CMS  11.5
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 {
35  protected ‪$siteFinder;
36 
38  {
39  $this->siteFinder = ‪$siteFinder;
40  parent::__construct();
41  }
42 
48  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
49  {
50  $io = new SymfonyStyle($input, ‪$output);
51  $sites = $this->siteFinder->getAllSites();
52 
53  if (empty($sites)) {
54  $io->title('No sites configured');
55  $io->note('Configure new sites in the "Sites" module.');
56  return 0;
57  }
58 
59  $io->title('All configured sites');
60  $table = new Table(‪$output);
61  $table->setHeaders([
62  'Identifier',
63  'Root PID',
64  'Base URL',
65  'Language',
66  'Locale',
67  'Status',
68  ]);
69  foreach ($sites as $site) {
70  $baseUrls = [];
71  $languages = [];
72  $locales = [];
73  $status = [];
74  foreach ($site->getLanguages() as $language) {
75  $baseUrls[] = (string)$language->getBase();
76  $languages[] = sprintf(
77  '%s (id:%d)',
78  $language->getTitle(),
79  $language->getLanguageId()
80  );
81  $locales[] = $language->getLocale();
82  $status[] = $language->isEnabled()
83  ? '<fg=green>enabled</>'
84  : '<fg=yellow>disabled</>';
85  }
86  $table->addRow(
87  [
88  '<options=bold>' . $site->getIdentifier() . '</>',
89  $site->getRootPageId(),
90  implode("\n", $baseUrls),
91  implode("\n", $languages),
92  implode("\n", $locales),
93  implode("\n", $status),
94  ]
95  );
96  }
97  $table->render();
98  return 0;
99  }
100 }
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Command\SiteListCommand\$siteFinder
‪SiteFinder $siteFinder
Definition: SiteListCommand.php:34
‪TYPO3\CMS\Core\Command\SiteListCommand\__construct
‪__construct(SiteFinder $siteFinder)
Definition: SiteListCommand.php:36
‪TYPO3\CMS\Core\Command\SiteListCommand
Definition: SiteListCommand.php:31
‪TYPO3\CMS\Core\Command\SiteListCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SiteListCommand.php:47
‪$output
‪$output
Definition: annotationChecker.php:121
‪TYPO3\CMS\Core\Command
Definition: CacheFlushCommand.php:18