minor #14351 [WebProfilerBundle] [HttpKernel] A static approach to version feedback (derrabus)

This PR was squashed before being merged into the 2.7 branch (closes #14351).

Discussion
----------

[WebProfilerBundle] [HttpKernel] A static approach to version feedback

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14349, #13626
| License       | MIT
| Doc PR        | N/A

This is an alternative approach for the version feedback feature of PR #13626. The original PR performed a server-side HTTP request to symfony.com, which might be problematic in certain environments, see #14349.

This PR makes the following assumptions:

* Symfony's release roadmap is rarely changed
* After the first release of a branch, the Symfony development team is committed to the announced support dates.
* The support period of a stable  branch might be extended, but it's usually not reduced.

Given those assumptions, the EOM and EOL dates may be shipped with the Symfony release and may be updated with a later bugfix release. The information would be available offline without any need to query Symfony's servers.

If the user is running the latest bugfix release of a branch, the EOM/EOL dates should be accurate. If he's running an earlier version, he might get a false positive warning about reaching EOM or EOL if the support period has been extended in the meantime. But since he's running an outdated version anyway, would this really be a problem?

Commits
-------

f5f3bba [WebProfilerBundle] [HttpKernel] A static approach to version feedback
This commit is contained in:
Tobias Schultze 2015-04-28 21:15:25 +02:00
commit 7389aa1cb8
2 changed files with 16 additions and 53 deletions

View File

@ -83,7 +83,7 @@ class ConfigDataCollector extends DataCollector
$this->data['bundles'][$name] = $bundle->getPath();
}
$this->data['symfony_state'] = $this->requestSymfonyState();
$this->data['symfony_state'] = $this->determineSymfonyState();
}
}
@ -268,62 +268,22 @@ class ConfigDataCollector extends DataCollector
/**
* Tries to retrieve information about the current Symfony version.
*
* @return string One of: unknown, dev, stable, eom, eol
* @return string One of: dev, stable, eom, eol
*/
private function requestSymfonyState()
private function determineSymfonyState()
{
$versionInfo = null;
$now = new \DateTime();
$eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
$eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
// 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);
if ($now > $eol) {
$versionState = 'eol';
} elseif ($now > $eom) {
$versionState = 'eom';
} elseif ('' !== Kernel::EXTRA_VERSION) {
$versionState = 'dev';
} 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));
$versionState = 'stable';
}
return $versionState;

View File

@ -67,6 +67,9 @@ abstract class Kernel implements KernelInterface, TerminableInterface
const RELEASE_VERSION = '0';
const EXTRA_VERSION = 'DEV';
const END_OF_MAINTENANCE = '05/2018';
const END_OF_LIFE = '05/2019';
/**
* Constructor.
*