8000 bug #10308 [Debug] enhance non-PSR-0 compatibility for case mismatch … · symfony/symfony@a820930 · GitHub
[go: up one dir, main page]

Skip to content

Commit a820930

Browse files
committed
bug #10308 [Debug] enhance non-PSR-0 compatibility for case mismatch test (nicolas-grekas)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Debug] enhance non-PSR-0 compatibility for case mismatch test | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | no Fix compatibility with non-PSR-0/4 loading schemes. See #10201 (comment) Commits ------- 120e197 [Debug] enhance non-PSR-0 compatibility for case mismatch test
2 parents ca4736b + 120e197 commit a820930

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,30 @@ public function loadClass($class)
176176
$class = substr($class, 1);
177177
}
178178

179-
$i = -1;
180-
$tail = str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
179+
$i = 0;
180+
$tail = DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
181181
$len = strlen($tail);
182182

183183
do {
184-
$tail = substr($tail, $i+1);
185-
$len -= $i+1;
186-
187-
if (! substr_compare($file, $tail, -$len, $len, true) && substr_compare($file, $tail, -$len, $len, false)) {
188-
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
184+
$tail = substr($tail, $i);
185+
$len -= $i;
186+
187+
if (0 === substr_compare($file, $tail, -$len, $len, true)) {
188+
if (0 !== substr_compare($file, $tail, -$len, $len, false)) {
189+
if (method_exists($this->classLoader[0], 'getClassMap')) {
190+
$map = $this->classLoader[0]->getClassMap();
191+
} else {
192+
$map = array();
193+
}
194+
195+
if (! isset($map[$class])) {
196+
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
197+
}
198+
}
199+
200+
break;
189201
}
190-
} while (false !== $i = strpos($tail, '\\'));
202+
} while (false !== $i = strpos($tail, DIRECTORY_SEPARATOR, 1));
191203

192204
if (! $exists) {
193205
if (false !== strpos($class, '/')) {

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ public function testFileCaseMismatch()
140140
{
141141
class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true);
142142
}
143+
144+
/**
145+
* @expectedException \RuntimeException
146+
*/
147+
public function testPsr4CaseMismatch()
148+
{
149+
class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true);
150+
}
151+
152+
public function testNotPsr0()
153+
{
154+
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0', true));
155+
}
156+
157+
public function testNotPsr0Bis()
158+
{
159+
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0bis', true));
160+
}
143161
}
144162

145163
class ClassLoader
@@ -148,6 +166,11 @@ public function loadClass($class)
148166
{
149167
}
150168

169+
public function getClassMap()
170+
{
171+
return array(__NAMESPACE__.'\Fixtures\NotPSR0bis' => __DIR__ . '/Fixtures/notPsr0Bis.php');
172+
}
173+
151174
public function findFile($class)
152175
{
153176
if (__NAMESPACE__.'\TestingUnsilencing' === $class) {
@@ -158,6 +181,12 @@ public function findFile($class)
158181
eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}');
159182
} elseif (__NAMESPACE__.'\Fixtures\CaseMismatch' === $class) {
160183
return __DIR__ . '/Fixtures/casemismatch.php';
184+
} elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) {
185+
return __DIR__ . '/Fixtures/psr4/Psr4CaseMismatch.php';
186+
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0' === $class) {
187+
return __DIR__ . '/Fixtures/reallyNotPsr0.php';
188+
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
189+
return __DIR__ . '/Fixtures/notPsr0Bis.php';
161190
}
162191
}
163192
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
class NotPSR0bis
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
class PSR4CaseMismatch
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
class NotPSR0
6+
{
7+
}

0 commit comments

Comments
 (0)
0