Skip to content

Commit adfec18

Browse files
Merge branch '3.1' into 3.2
* 3.1: Fix getMock usage Remove dead code [Form] DateTimeToLocalizedStringTransformer does not use TZ when using only date [Validator] Fix caching of constraints derived from non-serializable parents [TwigBundle] Fix bug where namespaced paths don't take parent bundles in account [FrameworkBundle] Fix relative paths used as cache keys respect groups when merging constraints fix IPv6 address handling in server commands
2 parents d0ce87e + 4265e07 commit adfec18

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Command/ServerCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ protected function isOtherServerProcessRunning($address)
5454
return true;
5555
}
5656

57-
list($hostname, $port) = explode(':', $address);
57+
$pos = strrpos($address, ':');
58+
$hostname = substr($address, 0, $pos);
59+
$port = substr($address, $pos + 1);
5860

5961
$fp = @fsockopen($hostname, $port, $errno, $errstr, 5);
6062

Templating/Loader/TemplateLocator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TemplateLocator implements FileLocatorInterface
2424
protected $locator;
2525
protected $cache;
2626

27+
private $cacheHits = array();
28+
2729
/**
2830
* Constructor.
2931
*
@@ -71,12 +73,15 @@ public function locate($template, $currentPath = null, $first = true)
7173

7274
$key = $this->getCacheKey($template);
7375

76+
if (isset($this->cacheHits[$key])) {
77+
return $this->cacheHits[$key];
78+
}
7479
if (isset($this->cache[$key])) {
75-
return $this->cache[$key];
80+
return $this->cacheHits[$key] = realpath($this->cache[$key]) ?: $this->cache[$key];
7681
}
7782

7883
try {
79-
return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
84+
return $this->cacheHits[$key] = $this->locator->locate($template->getPath(), $currentPath);
8085
} catch (\InvalidArgumentException $e) {
8186
throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
8287
}

Tests/Fixtures/templates.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return array(
4+
'bundle:controller:name.format.engine' => __DIR__.'/../Fixtures/Resources/views/this.is.a.template.format.engine',
5+
);

Tests/Templating/Loader/TemplateLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ public function testLocateATemplate()
3838
$this->assertEquals('/path/to/template', $locator->locate($template));
3939
}
4040

41+
public function testLocateATemplateFromCacheDir()
42+
{
43+
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');
44+
45+
$fileLocator = $this->getFileLocator();
46+
47+
$locator = new TemplateLocator($fileLocator, __DIR__.'/../../Fixtures');
48+
49+
$this->assertEquals(realpath(__DIR__.'/../../Fixtures/Resources/views/this.is.a.template.format.engine'), $locator->locate($template));
50+
}
51+
4152
public function testThrowsExceptionWhenTemplateNotFound()
4253
{
4354
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');

0 commit comments

Comments
 (0)