Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5dcef29

Browse filesBrowse files
committed
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 ------- 2550eab [FrameworkBundle] Added about command
2 parents 940c29a + 2550eab commit 5dcef29
Copy full SHA for 5dcef29

File tree

1 file changed

+110
-0
lines changed
Filter options

1 file changed

+110
-0
lines changed
+110Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.