feature #19278 [FrameworkBundle] Added about command (ro0NL)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[FrameworkBundle] Added about command
| Q | A |
| --- | --- |
| Branch? | "master" |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any |
| License | MIT |
| Doc PR | reference to the documentation PR, if any |
![image](https://cloud.githubusercontent.com/assets/1047696/24218101/50c4ebe2-0f42-11e7-985d-b47fc8a6f520.png)
Commits
-------
2550eab43c
[FrameworkBundle] Added about command
This commit is contained in:
commit
5dcef29531
110
src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Normal file
110
src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper\Helper;
|
||||||
|
use Symfony\Component\Console\Helper\TableSeparator;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A console command to display information about the current installation.
|
||||||
|
*
|
||||||
|
* @author Roland Franssen <franssen.roland@gmail.com>
|
||||||
|
*/
|
||||||
|
class AboutCommand extends ContainerAwareCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('about')
|
||||||
|
->setDescription('Displays information about the current project')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
/** @var $kernel KernelInterface */
|
||||||
|
$kernel = $this->getContainer()->get('kernel');
|
||||||
|
$baseDir = realpath($kernel->getRootDir().DIRECTORY_SEPARATOR.'..');
|
||||||
|
$bundles = array_map(function ($bundle) use ($baseDir) {
|
||||||
|
return $bundle->getName();
|
||||||
|
}, $kernel->getBundles());
|
||||||
|
sort($bundles);
|
||||||
|
|
||||||
|
$io->table(array(), array(
|
||||||
|
array('<info>Symfony</>'),
|
||||||
|
new TableSeparator(),
|
||||||
|
array('Version', Kernel::VERSION),
|
||||||
|
array('End of maintenance', Kernel::END_OF_MAINTENANCE.(self::isExpired(Kernel::END_OF_MAINTENANCE) ? ' <error>Expired</>' : '')),
|
||||||
|
array('End of life', Kernel::END_OF_LIFE.(self::isExpired(Kernel::END_OF_LIFE) ? ' <error>Expired</>' : '')),
|
||||||
|
new TableSeparator(),
|
||||||
|
array('<info>Kernel</>'),
|
||||||
|
new TableSeparator(),
|
||||||
|
array('Type', get_class($kernel)),
|
||||||
|
array('Name', $kernel->getName()),
|
||||||
|
array('Environment', $kernel->getEnvironment()),
|
||||||
|
array('Debug', $kernel->isDebug() ? 'true' : 'false'),
|
||||||
|
array('Charset', $kernel->getCharset()),
|
||||||
|
array('Root directory', self::formatPath($kernel->getRootDir(), $baseDir)),
|
||||||
|
array('Cache directory', self::formatPath($kernel->getCacheDir(), $baseDir).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'),
|
||||||
|
array('Log directory', self::formatPath($kernel->getLogDir(), $baseDir).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'),
|
||||||
|
new TableSeparator(),
|
||||||
|
array('<info>PHP</>'),
|
||||||
|
new TableSeparator(),
|
||||||
|
array('Version', PHP_VERSION),
|
||||||
|
array('Architecture', (PHP_INT_SIZE * 8).' bits'),
|
||||||
|
array('Intl locale', \Locale::getDefault() ?: 'n/a'),
|
||||||
|
array('Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'),
|
||||||
|
array('OPcache', extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'),
|
||||||
|
array('APCu', extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'),
|
||||||
|
array('Xdebug', extension_loaded('xdebug') ? 'true' : 'false'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function formatPath($path, $baseDir = null)
|
||||||
|
{
|
||||||
|
return null !== $baseDir ? preg_replace('~^'.preg_quote($baseDir, '~').'~', '.', $path) : $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function formatFileSize($path)
|
||||||
|
{
|
||||||
|
if (is_file($path)) {
|
||||||
|
$size = filesize($path) ?: 0;
|
||||||
|
} else {
|
||||||
|
$size = 0;
|
||||||
|
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
|
||||||
|
$size += $file->getSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Helper::formatMemory($size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function isExpired($date)
|
||||||
|
{
|
||||||
|
$date = \DateTime::createFromFormat('m/Y', $date);
|
||||||
|
|
||||||
|
return false !== $date && new \DateTime() > $date->modify('last day of this month 23:59:59');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user