|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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 <[email protected]> |
| 26 | + */ |
| 27 | +class AboutCommand extends ContainerAwareCommand |
| 28 | +{ |
| 29 | + /** |
| 30 | + * {@inheritdoc} |
| 31 | + */ |
| 32 | + protected function configure() |
| 33 | + { |
| 34 | + $this |
| 35 | + ->setName('about') |
| 36 | + ->setDescription('Displays information about the current project') |
| 37 | + ; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * {@inheritdoc} |
| 42 | + */ |
| 43 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 44 | + { |
| 45 | + $io = new SymfonyStyle($input, $output); |
| 46 | + |
| 47 | + /** @var $kernel KernelInterface */ |
| 48 | + $kernel = $this->getContainer()->get('kernel'); |
| 49 | + $baseDir = realpath($kernel->getRootDir().DIRECTORY_SEPARATOR.'..'); |
| 50 | + $bundles = array_map(function ($bundle) use ($baseDir) { |
| 51 | + return $bundle->getName(); |
| 52 | + }, $kernel->getBundles()); |
| 53 | + sort($bundles); |
| 54 | + |
| 55 | + $io->table(array(), array( |
| 56 | + array('<info>Symfony</>'), |
| 57 | + new TableSeparator(), |
| 58 | + array('Version', Kernel::VERSION), |
| 59 | + array('End of maintenance', Kernel::END_OF_MAINTENANCE.(self::isExpired(Kernel::END_OF_MAINTENANCE) ? ' <error>Expired</>' : '')), |
| 60 | + array('End of life', Kernel::END_OF_LIFE.(self::isExpired(Kernel::END_OF_LIFE) ? ' <error>Expired</>' : '')), |
| 61 | + new TableSeparator(), |
| 62 | + array('<info>Kernel</>'), |
| 63 | + new TableSeparator(), |
| 64 | + array('Type', get_class($kernel)), |
| 65 | + array('Name', $kernel->getName()), |
| 66 | + array('Environment', $kernel->getEnvironment()), |
| 67 | + array('Debug', $kernel->isDebug() ? 'true' : 'false'), |
| 68 | + array('Charset', $kernel->getCharset()), |
| 69 | + array('Root directory', self::formatPath($kernel->getRootDir(), $baseDir)), |
| 70 | + array('Cache directory', self::formatPath($kernel->getCacheDir(), $baseDir).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'), |
| 71 | + array('Log directory', self::formatPath($kernel->getLogDir(), $baseDir).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'), |
| 72 | + new TableSeparator(), |
| 73 | + array('<info>PHP</>'), |
| 74 | + new TableSeparator(), |
| 75 | + array('Version', PHP_VERSION), |
| 76 | + array('Architecture', (PHP_INT_SIZE * 8).' bits'), |
| 77 | + array('Intl locale', \Locale::getDefault() ?: 'n/a'), |
| 78 | + array('Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'), |
| 79 | + array('OPcache', extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'), |
| 80 | + array('APCu', extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'), |
| 81 | + array('Xdebug', extension_loaded('xdebug') ? 'true' : 'false'), |
| 82 | + )); |
| 83 | + } |
| 84 | + |
| 85 | + private static function formatPath($path, $baseDir = null) |
| 86 | + { |
| 87 | + return null !== $baseDir ? preg_replace('~^'.preg_quote($baseDir, '~').'~', '.', $path) : $path; |
| 88 | + } |
| 89 | + |
| 90 | + private static function formatFileSize($path) |
| 91 | + { |
| 92 | + if (is_file($path)) { |
| 93 | + $size = filesize($path) ?: 0; |
| 94 | + } else { |
| 95 | + $size = 0; |
| 96 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) { |
| 97 | + $size += $file->getSize(); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + return Helper::formatMemory($size); |
| 102 | + } |
| 103 | + |
| 104 | + private static function isExpired($date) |
| 105 | + { |
| 106 | + $date = \DateTime::createFromFormat('m/Y', $date); |
| 107 | + |
| 108 | + return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59'); |
| 109 | + } |
| 110 | +} |
0 commit comments