"Fossies" - the Fresh Open Source Software Archive

Member "phplist-3.5.0/public_html/lists/base/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php" (1 Dec 2019, 5413 Bytes) of package /linux/www/phplist-3.5.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AboutCommand.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.4.7_vs_3.4.8.

    1 <?php
    2 
    3 /*
    4  * This file is part of the Symfony package.
    5  *
    6  * (c) Fabien Potencier <fabien@symfony.com>
    7  *
    8  * For the full copyright and license information, please view the LICENSE
    9  * file that was distributed with this source code.
   10  */
   11 
   12 namespace Symfony\Bundle\FrameworkBundle\Command;
   13 
   14 use Symfony\Component\Console\Helper\Helper;
   15 use Symfony\Component\Console\Helper\TableSeparator;
   16 use Symfony\Component\Console\Input\InputInterface;
   17 use Symfony\Component\Console\Output\OutputInterface;
   18 use Symfony\Component\Console\Style\SymfonyStyle;
   19 use Symfony\Component\HttpKernel\Kernel;
   20 use Symfony\Component\HttpKernel\KernelInterface;
   21 
   22 /**
   23  * A console command to display information about the current installation.
   24  *
   25  * @author Roland Franssen <franssen.roland@gmail.com>
   26  *
   27  * @final since version 3.4
   28  */
   29 class AboutCommand extends ContainerAwareCommand
   30 {
   31     protected static $defaultName = 'about';
   32 
   33     /**
   34      * {@inheritdoc}
   35      */
   36     protected function configure()
   37     {
   38         $this
   39             ->setDescription('Displays information about the current project')
   40             ->setHelp(<<<'EOT'
   41 The <info>%command.name%</info> command displays information about the current Symfony project.
   42 
   43 The <info>PHP</info> section displays important configuration that could affect your application. The values might
   44 be different between web and CLI.
   45 
   46 The <info>Environment</info> section displays the current environment variables managed by Symfony Dotenv. It will not
   47 be shown if no variables were found. The values might be different between web and CLI.
   48 EOT
   49             )
   50         ;
   51     }
   52 
   53     /**
   54      * {@inheritdoc}
   55      */
   56     protected function execute(InputInterface $input, OutputInterface $output)
   57     {
   58         $io = new SymfonyStyle($input, $output);
   59 
   60         /** @var $kernel KernelInterface */
   61         $kernel = $this->getApplication()->getKernel();
   62 
   63         $rows = [
   64             ['<info>Symfony</>'],
   65             new TableSeparator(),
   66             ['Version', Kernel::VERSION],
   67             ['End of maintenance', Kernel::END_OF_MAINTENANCE.(self::isExpired(Kernel::END_OF_MAINTENANCE) ? ' <error>Expired</>' : '')],
   68             ['End of life', Kernel::END_OF_LIFE.(self::isExpired(Kernel::END_OF_LIFE) ? ' <error>Expired</>' : '')],
   69             new TableSeparator(),
   70             ['<info>Kernel</>'],
   71             new TableSeparator(),
   72             ['Type', \get_class($kernel)],
   73             ['Name', $kernel->getName()],
   74             ['Environment', $kernel->getEnvironment()],
   75             ['Debug', $kernel->isDebug() ? 'true' : 'false'],
   76             ['Charset', $kernel->getCharset()],
   77             ['Root directory', self::formatPath($kernel->getRootDir(), $kernel->getProjectDir())],
   78             ['Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],
   79             ['Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'],
   80             new TableSeparator(),
   81             ['<info>PHP</>'],
   82             new TableSeparator(),
   83             ['Version', PHP_VERSION],
   84             ['Architecture', (PHP_INT_SIZE * 8).' bits'],
   85             ['Intl locale', class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'],
   86             ['Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'],
   87             ['OPcache', \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],
   88             ['APCu', \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],
   89             ['Xdebug', \extension_loaded('xdebug') ? 'true' : 'false'],
   90         ];
   91 
   92         if ($dotenv = self::getDotenvVars()) {
   93             $rows = array_merge($rows, [
   94                 new TableSeparator(),
   95                 ['<info>Environment (.env)</>'],
   96                 new TableSeparator(),
   97             ], array_map(function ($value, $name) {
   98                 return [$name, $value];
   99             }, $dotenv, array_keys($dotenv)));
  100         }
  101 
  102         $io->table([], $rows);
  103     }
  104 
  105     private static function formatPath($path, $baseDir = null)
  106     {
  107         return null !== $baseDir ? preg_replace('~^'.preg_quote($baseDir, '~').'~', '.', $path) : $path;
  108     }
  109 
  110     private static function formatFileSize($path)
  111     {
  112         if (is_file($path)) {
  113             $size = filesize($path) ?: 0;
  114         } else {
  115             $size = 0;
  116             foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
  117                 $size += $file->getSize();
  118             }
  119         }
  120 
  121         return Helper::formatMemory($size);
  122     }
  123 
  124     private static function isExpired($date)
  125     {
  126         $date = \DateTime::createFromFormat('d/m/Y', '01/'.$date);
  127 
  128         return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
  129     }
  130 
  131     private static function getDotenvVars()
  132     {
  133         $vars = [];
  134         foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
  135             if ('' !== $name && false !== $value = getenv($name)) {
  136                 $vars[$name] = $value;
  137             }
  138         }
  139 
  140         return $vars;
  141     }
  142 }