Skip to content

Commit c35743f

Browse files
authored
Merge pull request #28 from phug-php/allow-extension-redundancy
Allow extension redundancy
2 parents 1a1825a + 42c3c8f commit c35743f

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

.multi-tester.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
phug/renderer:
2+
script: vendor/bin/phpunit -c ./vendor/phug/dev-tool/config/
3+
4+
phug/phug:
5+
script: vendor/bin/phpunit -c ./vendor/phug/dev-tool/config/
6+
7+
pug-php/pug: default
8+
9+
pug/bemto: default
10+
11+
pug-php/pug-assets: default
12+
13+
pug-php/pug-minify: default
14+
15+
pug/slim: default
16+
17+
pug/twig:
18+
script: vendor/bin/phpunit -c ./vendor/phug/dev-tool/config/
19+
20+
ci-pug/ci-pug: default
21+
22+
bkwld/laravel-pug:
23+
install:
24+
- php tests/setDependenciesVersions.php 5.8.* ^3.0
25+
- composer update --no-interaction
26+
script: LARAVEL_VERSION=5.8 ./vendor/bin/phpunit --no-coverage
27+
28+
pug/yii2: default

.travis.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ language: php
44
git:
55
depth: 5
66

7-
php:
8-
- 5.5
9-
- 5.6
10-
- 7.0
11-
- 7.1
12-
- 7.2
13-
- 7.3
7+
matrix:
8+
include:
9+
- php: 5.5
10+
- php: 5.6
11+
- php: 7.0
12+
- php: 7.1
13+
- php: 7.2
14+
- php: 7.3
15+
- php: 7.3
16+
env: MULTITEST='on'
1417

1518
install:
1619
- travis_retry composer clear-cache
20+
- if [ "$MULTITEST" = "on" ]; then composer require --no-update kylekatarnls/multi-tester; fi;
1721
- travis_retry composer self-update
1822
- travis_retry composer install
1923

2024
script:
21-
- vendor/bin/phug-dev check --report --coverage-php-version=5.6
25+
- if [ "$MULTITEST" != "on" ]; then vendor/bin/phug-dev check --report --coverage-php-version=5.6; fi;
26+
- if [ "$MULTITEST" = "on" ]; then vendor/bin/multi-tester --verbose; fi;
2227

2328
notifications:
2429
slack: phug:nzXFnxhU14RWK2EQSDL0u08z

src/Phug/Compiler/Locator/FileLocator.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ private function normalize($path)
1111
return rtrim(str_replace('\\', '/', $path), '/');
1212
}
1313

14+
private function getFullPath($location, $path, $extension)
15+
{
16+
$fullPath = "$location/$path$extension";
17+
18+
if (@is_file($fullPath) && is_readable($fullPath)) {
19+
return realpath($fullPath);
20+
}
21+
22+
$length = strlen($extension);
23+
24+
if ($length && substr($path, $length) === $extension &&
25+
@is_file($fullPath = "$location/$path") && is_readable($fullPath)
26+
) {
27+
return realpath($fullPath);
28+
}
29+
30+
return null;
31+
}
32+
1433
public function locate($path, array $locations, array $extensions)
1534
{
1635
// @ catch softly PHP open_basedir restriction
@@ -25,10 +44,8 @@ public function locate($path, array $locations, array $extensions)
2544
$location = $this->normalize($location);
2645

2746
foreach ($extensions as $extension) {
28-
$fullPath = "$location/$path$extension";
29-
30-
if (@is_file($fullPath) && is_readable($fullPath)) {
31-
return realpath($fullPath);
47+
if ($fullPath = $this->getFullPath($location, $path, $extension)) {
48+
return $fullPath;
3249
}
3350
}
3451
}

tests/Phug/Compiler/Locator/FileLocatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FileLocatorTest extends AbstractCompilerTest
1212
{
1313
/**
1414
* @covers ::normalize
15+
* @covers ::getFullPath
1516
* @covers ::<public>
1617
*/
1718
public function testLocate()
@@ -27,6 +28,10 @@ public function testLocate()
2728
'/views/base.pug',
2829
str_replace('\\', '/', $locator->locate('base', $paths, $extensions))
2930
);
31+
self::assertStringEndsWith(
32+
'/views/base.pug',
33+
str_replace('\\', '/', $locator->locate('base.pug', $paths, $extensions))
34+
);
3035

3136
self::assertFileExists($locator->locate('../layouts/base', $paths, $extensions));
3237
self::assertStringEndsWith(

0 commit comments

Comments
 (0)