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

Skip to content

Commit 006c09a

Browse files
committed
Merge branch '4.4'
* 4.4: fix PHP 5.6 compatibility [Cache] fixed TagAwareAdapter returning invalid cache Add plus character `+` to legal mime subtype Make Symfony\Contracts\Service\Test\ServiceLocatorTest abstract bug #33942 [DI] Add extra type check to php dumper [Dotenv] search variable values in ENV first then env file [PropertyInfo] Respect property name case when guessing from public method name [VarDumper] fix resetting the "bold" state in CliDumper Missing argument in method_exists SCA: added missing break in a loop
2 parents ae7803d + ae808b0 commit 006c09a

File tree

12 files changed

+165
-23
lines changed

12 files changed

+165
-23
lines changed

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,14 @@ public function hasItem($key)
162162
if (!$this->pool->hasItem($key)) {
163163
return false;
164164
}
165-
if (!$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key)->get()) {
165+
166+
$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key);
167+
168+
if (!$itemTags->isHit()) {
169+
return false;
170+
}
171+
172+
if (!$itemTags = $itemTags->get()) {
166173
return true;
167174
}
168175

@@ -326,7 +333,10 @@ private function generateItems(iterable $items, array $tagKeys)
326333
}
327334

328335
unset($tagKeys[$key]);
329-
$itemTags[$key] = $item->get() ?: [];
336+
337+
if ($item->isHit()) {
338+
$itemTags[$key] = $item->get() ?: [];
339+
}
330340

331341
if (!$tagKeys) {
332342
$tagVersions = $this->getTagVersions($itemTags);

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,84 @@ public function testKnownTagVersionsTtl()
101101
$this->assertTrue($pool->getItem('foo')->isHit());
102102
}
103103

104+
public function testTagEntryIsCreatedForItemWithoutTags()
105+
{
106+
$pool = $this->createCachePool();
107+
108+
$itemKey = 'foo';
109+
$item = $pool->getItem($itemKey);
110+
$pool->save($item);
111+
112+
$adapter = new FilesystemAdapter();
113+
$this->assertTrue($adapter->hasItem(TagAwareAdapter::TAGS_PREFIX.$itemKey));
114+
}
115+
116+
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemTags()
117+
{
118+
$pool = $this->createCachePool();
119+
120+
$itemKey = 'foo';
121+
$item = $pool->getItem($itemKey);
122+
$pool->save($item);
123+
124+
$anotherPool = $this->createCachePool();
125+
126+
$adapter = new FilesystemAdapter();
127+
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
128+
129+
$this->assertFalse($anotherPool->hasItem($itemKey));
130+
}
131+
132+
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemTags()
133+
{
134+
$pool = $this->createCachePool();
135+
136+
$itemKey = 'foo';
137+
$item = $pool->getItem($itemKey);
138+
$pool->save($item);
139+
140+
$anotherPool = $this->createCachePool();
141+
142+
$adapter = new FilesystemAdapter();
143+
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
144+
145+
$item = $anotherPool->getItem($itemKey);
146+
$this->assertFalse($item->isHit());
147+
}
148+
149+
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
150+
{
151+
$pool = $this->createCachePool();
152+
153+
$itemKey = 'foo';
154+
$item = $pool->getItem($itemKey);
155+
$pool->save($item);
156+
157+
$anotherPool = $this->createCachePool();
158+
159+
$adapter = new FilesystemAdapter();
160+
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
161+
162+
$this->assertFalse($anotherPool->hasItem($itemKey));
163+
}
164+
165+
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
166+
{
167+
$pool = $this->createCachePool();
168+
169+
$itemKey = 'foo';
170+
$item = $pool->getItem($itemKey);
171+
$pool->save($item);
172+
173+
$anotherPool = $this->createCachePool();
174+
175+
$adapter = new FilesystemAdapter();
176+
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
177+
178+
$item = $anotherPool->getItem($itemKey);
179+
$this->assertFalse($item->isHit());
180+
}
181+
104182
/**
105183
* @return MockObject|PruneableCacheInterface
106184
*/

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ private function isSingleUsePrivateNode(ServiceReferenceGraphNode $node): bool
19551955
if (!$value = $edge->getSourceNode()->getValue()) {
19561956
continue;
19571957
}
1958-
if ($edge->isLazy() || !$value->isShared()) {
1958+
if ($edge->isLazy() || !$value instanceof Definition || !$value->isShared()) {
19591959
return false;
19601960
}
19611961
$ids[$edge->getSourceNode()->getId()] = true;

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ private function lexValue(): string
252252
throw $this->createFormatException('Whitespace are not supported before the value');
253253
}
254254

255+
$loadedVars = array_flip(explode(',', isset($_SERVER['SYMFONY_DOTENV_VARS']) ? $_SERVER['SYMFONY_DOTENV_VARS'] : (isset($_ENV['SYMFONY_DOTENV_VARS']) ? $_ENV['SYMFONY_DOTENV_VARS'] : '')));
256+
unset($loadedVars['']);
255257
$v = '';
256258

257259
do {
@@ -290,8 +292,8 @@ private function lexValue(): string
290292
++$this->cursor;
291293
$value = str_replace(['\\"', '\r', '\n'], ['"', "\r", "\n"], $value);
292294
$resolvedValue = $value;
293-
$resolvedValue = $this->resolveVariables($resolvedValue);
294-
$resolvedValue = $this->resolveCommands($resolvedValue);
295+
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
296+
$resolvedValue = $this->resolveCommands($resolvedValue, $loadedVars);
295297
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
296298
$v .= $resolvedValue;
297299
} else {
@@ -313,8 +315,8 @@ private function lexValue(): string
313315
}
314316
$value = rtrim($value);
315317
$resolvedValue = $value;
316-
$resolvedValue = $this->resolveVariables($resolvedValue);
317-
$resolvedValue = $this->resolveCommands($resolvedValue);
318+
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
319+
$resolvedValue = $this->resolveCommands($resolvedValue, $loadedVars);
318320
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
319321

320322
if ($resolvedValue === $value && preg_match('/\s+/', $value)) {
@@ -367,7 +369,7 @@ private function skipEmptyLines()
367369
}
368370
}
369371

370-
private function resolveCommands(string $value): string
372+
private function resolveCommands(string $value, array $loadedVars): string
371373
{
372374
if (false === strpos($value, '$')) {
373375
return $value;
@@ -383,7 +385,7 @@ private function resolveCommands(string $value): string
383385
)
384386
/x';
385387

386-
return preg_replace_callback($regex, function ($matches) {
388+
return preg_replace_callback($regex, function ($matches) use ($loadedVars) {
387389
if ('\\' === $matches[1]) {
388390
return substr($matches[0], 1);
389391
}
@@ -403,7 +405,14 @@ private function resolveCommands(string $value): string
403405
$process->inheritEnvironmentVariables();
404406
}
405407

406-
$process->setEnv($this->values);
408+
$env = [];
409+
foreach ($this->values as $name => $value) {
410+
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
411+
$env[$name] = $value;
412+
}
413+
}
414+
$process->setEnv($env);
415+
407416
try {
408417
$process->mustRun();
409418
} catch (ProcessException $e) {
@@ -414,7 +423,7 @@ private function resolveCommands(string $value): string
414423
}, $value);
415424
}
416425

417-
private function resolveVariables(string $value): string
426+
private function resolveVariables(string $value, array $loadedVars): string
418427
{
419428
if (false === strpos($value, '$')) {
420429
return $value;
@@ -431,7 +440,7 @@ private function resolveVariables(string $value): string
431440
(?P<closing_brace>\})? # optional closing brace
432441
/x';
433442

434-
$value = preg_replace_callback($regex, function ($matches) {
443+
$value = preg_replace_callback($regex, function ($matches) use ($loadedVars) {
435444
// odd number of backslashes means the $ character is escaped
436445
if (1 === \strlen($matches['backslashes']) % 2) {
437446
return substr($matches[0], 1);
@@ -447,14 +456,16 @@ private function resolveVariables(string $value): string
447456
}
448457

449458
$name = $matches['name'];
450-
if (isset($this->values[$name])) {
459+
if (isset($loadedVars[$name]) && isset($this->values[$name])) {
451460
$value = $this->values[$name];
452-
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
453-
$value = $_SERVER[$name];
454461
} elseif (isset($_ENV[$name])) {
455462
$value = $_ENV[$name];
463+
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
464+
$value = $_SERVER[$name];
465+
} elseif (isset($this->values[$name])) {
466+
$value = $this->values[$name];
456467
} else {
457-
$value = (string) getenv($name);
468+
$value = '';
458469
}
459470

460471
if ('' === $value && isset($matches['default_value'])) {

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testParse($data, $expected)
7272
public function getEnvData()
7373
{
7474
putenv('LOCAL=local');
75+
$_ENV['LOCAL'] = 'local';
7576
$_ENV['REMOTE'] = 'remote';
7677
$_SERVER['SERVERVAR'] = 'servervar';
7778

@@ -424,6 +425,22 @@ public function testOverridingEnvVarsWithNamesMemorizedInSpecialVar()
424425
$this->assertSame('/var/www', getenv('DOCUMENT_ROOT'));
425426
}
426427

428+
public function testGetVariablesValueFromEnvFirst()
429+
{
430+
$_ENV['APP_ENV'] = 'prod';
431+
$dotenv = new Dotenv(true);
432+
433+
$test = "APP_ENV=dev\nTEST1=foo1_\${APP_ENV}";
434+
$values = $dotenv->parse($test);
435+
$this->assertSame('foo1_prod', $values['TEST1']);
436+
437+
if ('\\' !== \DIRECTORY_SEPARATOR) {
438+
$test = "APP_ENV=dev\nTEST2=foo2_\$(php -r 'echo \$_SERVER[\"APP_ENV\"];')";
439+
$values = $dotenv->parse($test);
440+
$this->assertSame('foo2_prod', $values['TEST2']);
441+
}
442+
}
443+
427444
public function testNoDeprecationWarning()
428445
{
429446
$dotenv = new Dotenv(true);

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private static function normalizeHeaders(array $headers): array
199199
$normalizedHeaders = [];
200200

201201
foreach ($headers as $name => $values) {
202-
if (\is_object($values) && method_exists('__toString')) {
202+
if (\is_object($values) && method_exists($values, '__toString')) {
203203
$values = (string) $values;
204204
}
205205

src/Symfony/Component/Mime/FileBinaryMimeTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function guessMimeType(string $path): ?string
8383

8484
$type = trim(ob_get_clean());
8585

86-
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
86+
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) {
8787
// it's not a type, but an error message
8888
return null;
8989
}

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function getProperties(string $class, array $context = []): ?array
119119
if (!$propertyName || isset($properties[$propertyName])) {
120120
continue;
121121
}
122-
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
123-
$propertyName = lcfirst($propertyName);
122+
if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) {
123+
$propertyName = $lowerCasedPropertyName;
124124
}
125125
$properties[$propertyName] = $propertyName;
126126
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function testGetProperties()
6767
'123',
6868
'self',
6969
'realParent',
70+
'xTotals',
71+
'YT',
7072
'c',
7173
'd',
7274
'e',

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ class Dummy extends ParentDummy
9393
*/
9494
public $j;
9595

96+
/**
97+
* @var array
98+
*/
99+
private $xTotals;
100+
101+
/**
102+
* @var string
103+
*/
104+
private $YT;
105+
96106
/**
97107
* This should not be removed.
98108
*
@@ -181,4 +191,18 @@ public function setSelf(self $self)
181191
public function setRealParent(parent $realParent)
182192
{
183193
}
194+
195+
/**
196+
* @return array
197+
*/
198+
public function getXTotals()
199+
{
200+
}
201+
202+
/**
203+
* @return string
204+
*/
205+
public function getYT()
206+
{
207+
}
184208
}

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CliDumper extends AbstractDumper
2828
protected $maxStringWidth = 0;
2929
protected $styles = [
3030
// See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
31-
'default' => '38;5;208',
31+
'default' => '0;38;5;208',
3232
'num' => '1;38;5;38',
3333
'const' => '1;38;5;208',
3434
'str' => '1;38;5;113',

src/Symfony/Contracts/Service/Test/ServiceLocatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use Psr\Container\ContainerInterface;
1616
use Symfony\Contracts\Service\ServiceLocatorTrait;
1717

18-
class ServiceLocatorTest extends TestCase
18+
abstract class ServiceLocatorTest extends TestCase
1919
{
20-
public function getServiceLocator(array $factories)
20+
protected function getServiceLocator(array $factories)
2121
{
2222
return new class($factories) implements ContainerInterface {
2323
use ServiceLocatorTrait;

0 commit comments

Comments
 (0)