Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7389aa1

Browse files
committed
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
2 parents 17ee6a6 + f5f3bba commit 7389aa1

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function collect(Request $request, Response $response, \Exception $except
8383
$this->data['bundles'][$name] = $bundle->getPath();
8484
}
8585

86-
$this->data['symfony_state'] = $this->requestSymfonyState();
86+
$this->data['symfony_state'] = $this->determineSymfonyState();
8787
}
8888
}
8989

@@ -268,62 +268,22 @@ public function getName()
268268
/**
269269
* Tries to retrieve information about the current Symfony version.
270270
*
271-
* @return string One of: unknown, dev, stable, eom, eol
271+
* @return string One of: dev, stable, eom, eol
272272
*/
273-
private function requestSymfonyState()
273+
private function determineSymfonyState()
274274
{
275-
$versionInfo = null;
276-
277-
// get version information from cache or the roadmap
278-
$versionCachePath = $this->kernel->getCacheDir().'/version_info.json';
279-
if (file_exists($versionCachePath)) {
280-
$versionInfo = json_decode(file_get_contents($versionCachePath), true);
275+
$now = new \DateTime();
276+
$eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
277+
$eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
278+
279+
if ($now > $eol) {
280+
$versionState = 'eol';
281+
} elseif ($now > $eom) {
282+
$versionState = 'eom';
283+
} elseif ('' !== Kernel::EXTRA_VERSION) {
284+
$versionState = 'dev';
281285
} else {
282-
$versionResponse = @file_get_contents('http://symfony.com/roadmap.json?version='.preg_replace('/^(\d+\.\d+).*/', '\\1', $this->data['symfony_version']));
283-
284-
if (false !== $versionResponse) {
285-
$versionInfo = json_decode($versionResponse, true);
286-
287-
if (isset($versionInfo['error_message'])) {
288-
// wrong version
289-
$versionInfo = null;
290-
}
291-
}
292-
}
293-
294-
// get the version state
295-
$versionState = 'unknown';
296-
if (null !== $versionInfo) {
297-
$now = new \DateTime();
298-
$eom = \DateTime::createFromFormat('m/Y', $versionInfo['eom'])->modify('last day of this month');
299-
$eol = \DateTime::createFromFormat('m/Y', $versionInfo['eol'])->modify('last day of this month');
300-
301-
if ($now > $eom) {
302-
$versionState = 'eom';
303-
} elseif ($now > $eol) {
304-
$versionState = 'eol';
305-
} elseif ('DEV' === Kernel::EXTRA_VERSION) {
306-
$versionState = 'dev';
307-
} else {
308-
$versionState = 'stable';
309-
}
310-
}
311-
312-
// invalidate or create cache
313-
if (null === $versionInfo) {
314-
// nothing to cache
315-
} elseif (isset($versionInfo['previous_state'])) {
316-
if ($versionInfo['previous_state'] !== $versionState) {
317-
// state changed => invalidate the cache
318-
unlink($versionCachePath);
319-
}
320-
} elseif (substr(Kernel::VERSION, 0, 3) !== $versionInfo['version']) {
321-
// version changed => invalidate the cache
322-
unlink($versionCachePath);
323-
} elseif ($this->cacheVersionInfo) {
324-
// no cache yet
325-
$versionInfo['previous_state'] = $versionState;
326-
file_put_contents($versionCachePath, json_encode($versionInfo));
286+
$versionState = 'stable';
327287
}
328288

329289
return $versionState;

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ abstract class Kernel implements KernelInterface, TerminableInterface
6767
const RELEASE_VERSION = '0';
6868
const EXTRA_VERSION = 'DEV';
6969

70+
const END_OF_MAINTENANCE = '05/2018';
71+
const END_OF_LIFE = '05/2019';
72+
7073
/**
7174
* Constructor.
7275
*

0 commit comments

Comments
 (0)