-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Added about command #19278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fabpot
merged 1 commit into
symfony:master
from
ro0NL:frameworkbundle/kernel-info-command
Mar 22, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
6581 | 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'); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Displaying this information can be misleading as it can be different from the PHP used by the web server. People should use
php
itself to get this information. I would restrict the information to what is really specific to Symfony.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows the same info as WDT configuration panel does.. 🤔 which was the basic idea; to mimic this on CLI, so you can actually spot differences at first sight.
I dropped the bundle list (sounds reasonable), the version ID and an additional table separator.
I think it looks pretty clean :))