bug #39091 [Config] Recheck glob brace support after GlobResource was serialized (wouterj)

This PR was merged into the 4.4 branch.

Discussion
----------

[Config] Recheck glob brace support after GlobResource was serialized

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

cc @bastnic

This bug was reported on Symfony Slack: `$this->globBrace` is set to `null` after unserialization from the `.meta` file.

Instead of serializing this property, I decided to reinitialize the property after unserialization. I think that's a safer option (e.g. it works when the cache is build on a different server with different globBrace support than the one running the application).

Commits
-------

d9534779cf Reinitialize globBrace after unserialization
This commit is contained in:
Alexander M. Turek 2020-11-16 15:38:21 +01:00
commit cf70d3a180
2 changed files with 21 additions and 0 deletions

View File

@ -94,6 +94,14 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes'];
}
/**
* @internal
*/
public function __wakeup(): void
{
$this->globBrace = \defined('GLOB_BRACE') ? \GLOB_BRACE : 0;
}
/**
* @return \Traversable
*/

View File

@ -194,4 +194,17 @@ class GlobResourceTest extends TestCase
$this->assertSame([], array_keys(iterator_to_array($resource)));
}
public function testSerializeUnserialize()
{
$dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
$resource = new GlobResource($dir, '/Resource', true);
$newResource = unserialize(serialize($resource));
$p = new \ReflectionProperty($resource, 'globBrace');
$p->setAccessible(true);
$this->assertEquals($p->getValue($resource), $p->getValue($newResource));
}
}