Skip to content

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

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data['bundles'][$name] = $bundle->getPath();
}

$this->data['symfony_state'] = $this->requestSymfonyState();
$this->data['symfony_state'] = $this->determineSymfonyState();
}
}

Expand Down Expand Up @@ -268,62 +268,22 @@ public function getName()
/**
* 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;

// 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);
$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');

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;
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down