Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 335381b

Browse filesBrowse files
committed
[PropertyInfo] PSR-6 cache
1 parent 4008130 commit 335381b
Copy full SHA for 335381b

File tree

3 files changed

+50
-20
lines changed
Filter options

3 files changed

+50
-20
lines changed

‎src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/PropertyInfoCacheExtractor.php
+27-8Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,41 @@ private function extract($method, array $arguments)
112112
return $this->arrayCache[$key];
113113
}
114114

115-
if ($value = $this->cacheItemPool->getItem($key)) {
116-
return $this->arrayCache[$key] = $value;
115+
$item = $this->cacheItemPool->getItem($key);
116+
117+
if ($item->isHit()) {
118+
return $this->arrayCache[$key] = $item->get();
117119
}
118120

119121
$value = call_user_func_array(array($this->propertyInfoExtractor, $method), $arguments);
120-
$this->cacheItemPool->save($key, $value);
122+
$item->set($value);
123+
$this->cacheItemPool->save($item);
121124

122125
return $this->arrayCache[$key] = $value;
123126
}
124127

128+
/**
129+
* Escapes a key according to PSR-6.
130+
*
131+
* Replaces characters forbidden by PSR-6 and the _ char by the _ char followed by the ASCII
132+
* code of the escaped char.
133+
*
134+
* @param string $key
135+
*
136+
* @return string
137+
*/
125138
private function escape($key)
126139
{
127-
str_replace(
128-
array('_', '{', '}', '(', ')', '/', '\\', '@', ':'),
129-
array('_95', '_123', '_125', '_40', '_41', '_47', '_92', '_64', '_58'),
130-
$key
131-
);
140+
return strtr($key, array(
141+
'{' => '_123',
142+
'}' => '_125',
143+
'(' => '_40',
144+
')' => '_41',
145+
'/' => '_47',
146+
'\\' => '_92',
147+
'@' => '_64',
148+
':' => '_58',
149+
'_' => '_95',
150+
));
132151
}
133152
}

‎src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/PropertyInfoCacheExtractorTest.php
+21-10Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Tests;
1313

14+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1415
use Symfony\Component\PropertyInfo\PropertyInfoCacheExtractor;
1516

1617
/**
@@ -22,7 +23,7 @@ public function setUp()
2223
{
2324
parent::setUp();
2425

25-
$this->propertyInfo = new PropertyInfoCacheExtractor($this->propertyInfo, new ArrayCac);
26+
$this->propertyInfo = new PropertyInfoCacheExtractor($this->propertyInfo, new ArrayAdapter());
2627
}
2728

2829
public function testCache()
@@ -36,18 +37,28 @@ public function testNotSerializableContext()
3637
$this->assertSame('short', $this->propertyInfo->getShortDescription('Foo', 'bar', array('foo' => function () {})));
3738
}
3839

39-
public function testEscape()
40+
/**
41+
* @dataProvider escapeDataProvider
42+
*/
43+
public function testEscape($toEscape, $expected)
4044
{
4145
$reflectionMethod = new \ReflectionMethod($this->propertyInfo, 'escape');
4246
$reflectionMethod->setAccessible(true);
4347

44-
$this->assertSame('foo_bar', $this->propertyInfo->escape('foo_95bar'));
45-
$this->assertSame('foo_95bar', $this->propertyInfo->escape('foo_9595bar'));
46-
$this->assertSame('foo{bar}', $this->propertyInfo->escape('foo_123bar_125'));
47-
$this->assertSame('foo(bar)', $this->propertyInfo->escape('foo_40bar_41'));
48-
$this->assertSame('foo/bar', $this->propertyInfo->escape('foo_47bar'));
49-
$this->assertSame('foo\bar', $this->propertyInfo->escape('foo_92bar'));
50-
$this->assertSame('foo@bar', $this->propertyInfo->escape('foo_64bar'));
51-
$this->assertSame('foo:bar', $this->propertyInfo->escape('foo_58bar'));
48+
$this->assertSame($expected, $reflectionMethod->invoke($this->propertyInfo, $toEscape));
49+
}
50+
51+
public function escapeDataProvider()
52+
{
53+
return array(
54+
array('foo_bar', 'foo_95bar'),
55+
array('foo_95bar', 'foo_9595bar'),
56+
array('foo{bar}', 'foo_123bar_125'),
57+
array('foo(bar)', 'foo_40bar_41'),
58+
array('foo/bar', 'foo_47bar'),
59+
array('foo\bar', 'foo_92bar'),
60+
array('foo@bar', 'foo_64bar'),
61+
array('foo:bar', 'foo_58bar'),
62+
);
5263
}
5364
}

‎src/Symfony/Component/PropertyInfo/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
},
2828
"require-dev": {
2929
"symfony/serializer": "~2.8|~3.0",
30+
"symfony/cache": "~3.1",
3031
"phpdocumentor/reflection": "^1.0.7",
3132
"doctrine/annotations": "~1.0",
32-
"doctrine/cache": "~1.0"
3333
},
3434
"conflict": {
3535
"phpdocumentor/reflection": "<1.0.7"
3636
},
3737
"suggest": {
38-
"doctrine/cache": "To cache results",
38+
"symfony/cache": "To cache results",
3939
"symfony/doctrine-bridge": "To use Doctrine metadata",
4040
"phpdocumentor/reflection": "To use the PHPDoc",
4141
"symfony/serializer": "To use Serializer metadata"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.