feature #13626 [WebProfilerBundle] Added feedback about the current symfony version (WouterJ)
This PR was merged into the 2.7 branch.
Discussion
----------
[WebProfilerBundle] Added feedback about the current symfony version
Description
---
This PR adds some visual and textual information about the Symfony version that is currently used. It'll indicate when the used version has reached eom or eol. I hope this will make people more aware of the fact that they should update (as I've seen quite some people using completely outdated Symfony versions).
Screenshot
---
![sf-toolbar-version-info](https://cloud.githubusercontent.com/assets/749025/6099512/da59c99e-affa-11e4-8093-173857901769.png)
PR Information
---
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes (didn't test though)
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
a4551f9
Added feedback about the current symfony version
This commit is contained in:
commit
d84f03d982
@ -9,7 +9,18 @@
|
||||
{% if collector.applicationname %}
|
||||
{{ collector.applicationname }} {{ collector.applicationversion }}
|
||||
{% else %}
|
||||
{{ collector.symfonyversion }}
|
||||
{% if 'unknown' == collector.symfonyState -%}
|
||||
<span class="sf-toolbar-status sf-toolbar-info-piece-additional" title="Unable to retrieve information about the Symfony version.">
|
||||
{%- elseif 'eol' == collector.symfonyState -%}
|
||||
<span class="sf-toolbar-status sf-toolbar-status-red" title="This Symfony version will no longer receive security fixes.">
|
||||
{%- elseif 'eom' == collector.symfonyState -%}
|
||||
<span class="sf-toolbar-status sf-toolbar-status-yellow" title="This Symfony version will only receive security fixes.">
|
||||
{%- elseif 'dev' == collector.symfonyState -%}
|
||||
<span class="sf-toolbar-status sf-toolbar-status-yellow" title="This Symfony version is still in the development phase.">
|
||||
{%- else -%}
|
||||
<span class="sf-toolbar-status sf-toolbar-status-green">
|
||||
{%- endif -%}
|
||||
{{ collector.symfonyversion }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</a>
|
||||
|
@ -23,9 +23,13 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*/
|
||||
class ConfigDataCollector extends DataCollector
|
||||
{
|
||||
/**
|
||||
* @var KernelInterface
|
||||
*/
|
||||
private $kernel;
|
||||
private $name;
|
||||
private $version;
|
||||
private $cacheVersionInfo = true;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -59,6 +63,7 @@ class ConfigDataCollector extends DataCollector
|
||||
'app_version' => $this->version,
|
||||
'token' => $response->headers->get('X-Debug-Token'),
|
||||
'symfony_version' => Kernel::VERSION,
|
||||
'symfony_state' => 'unknown',
|
||||
'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
|
||||
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
|
||||
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
|
||||
@ -77,6 +82,8 @@ class ConfigDataCollector extends DataCollector
|
||||
foreach ($this->kernel->getBundles() as $name => $bundle) {
|
||||
$this->data['bundles'][$name] = $bundle->getPath();
|
||||
}
|
||||
|
||||
$this->data['symfony_state'] = $this->requestSymfonyState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +117,21 @@ class ConfigDataCollector extends DataCollector
|
||||
return $this->data['symfony_version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state of the current Symfony release.
|
||||
*
|
||||
* @return string One of: unknown, dev, stable, eom, eol
|
||||
*/
|
||||
public function getSymfonyState()
|
||||
{
|
||||
return $this->data['symfony_state'];
|
||||
}
|
||||
|
||||
public function setCacheVersionInfo($cacheVersionInfo)
|
||||
{
|
||||
$this->cacheVersionInfo = $cacheVersionInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PHP version.
|
||||
*
|
||||
@ -242,4 +264,68 @@ class ConfigDataCollector extends DataCollector
|
||||
{
|
||||
return 'config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to retrieve information about the current Symfony version.
|
||||
*
|
||||
* @return string One of: unknown, dev, stable, eom, eol
|
||||
*/
|
||||
private function requestSymfonyState()
|
||||
{
|
||||
$versionInfo = null;
|
||||
|
||||
// get version information from cache or the roadmap
|
||||
$versionCachePath = $this->kernel->getCacheDir().'/version_info.json';
|
||||
if (file_exists($versionCachePath)) {
|
||||
$versionInfo = json_decode(file_get_contents($versionCachePath), true);
|
||||
} else {
|
||||
$versionResponse = @file_get_contents('http://symfony.com/roadmap.json?version='.preg_replace('/^(\d+\.\d+).*/', '\\1', $this->data['symfony_version']));
|
||||
|
||||
if (false !== $versionResponse) {
|
||||
$versionInfo = json_decode($versionResponse, true);
|
||||
|
||||
if (isset($versionInfo['error_message'])) {
|
||||
// wrong version
|
||||
$versionInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the version state
|
||||
$versionState = 'unknown';
|
||||
if (null !== $versionInfo) {
|
||||
$now = new \DateTime();
|
||||
$eom = \DateTime::createFromFormat('m/Y', $versionInfo['eom'])->modify('last day of this month');
|
||||
$eol = \DateTime::createFromFormat('m/Y', $versionInfo['eol'])->modify('last day of this month');
|
||||
|
||||
if ($now > $eom) {
|
||||
$versionState = 'eom';
|
||||
} elseif ($now > $eol) {
|
||||
$versionState = 'eol';
|
||||
} elseif ('DEV' === Kernel::EXTRA_VERSION) {
|
||||
$versionState = 'dev';
|
||||
} else {
|
||||
$versionState = 'stable';
|
||||
}
|
||||
}
|
||||
|
||||
// invalidate or create cache
|
||||
if (null === $versionInfo) {
|
||||
// nothing to cache
|
||||
} elseif (isset($versionInfo['previous_state'])) {
|
||||
if ($versionInfo['previous_state'] !== $versionState) {
|
||||
// state changed => invalidate the cache
|
||||
unlink($versionCachePath);
|
||||
}
|
||||
} elseif (substr(Kernel::VERSION, 0, 3) !== $versionInfo['version']) {
|
||||
// version changed => invalidate the cache
|
||||
unlink($versionCachePath);
|
||||
} elseif ($this->cacheVersionInfo) {
|
||||
// no cache yet
|
||||
$versionInfo['previous_state'] = $versionState;
|
||||
file_put_contents($versionCachePath, json_encode($versionInfo));
|
||||
}
|
||||
|
||||
return $versionState;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class ConfigDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$kernel = new KernelForTest('test', true);
|
||||
$c = new ConfigDataCollector();
|
||||
$c->setCacheVersionInfo(false);
|
||||
$c->setKernel($kernel);
|
||||
$c->collect(new Request(), new Response());
|
||||
|
||||
|
Reference in New Issue
Block a user