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

[Debug] enhance non-PSR-0 compatibility for case mismatch test #10308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions 28 src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,30 @@ public function loadClass($class)
$class = substr($class, 1);
}

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

do {
$tail = substr($tail, $i+1);
$len -= $i+1;

if (! substr_compare($file, $tail, -$len, $len, true) && substr_compare($file, $tail, -$len, $len, false)) {
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
$tail = substr($tail, $i);
$len -= $i;

if (0 === substr_compare($file, $tail, -$len, $len, true)) {
if (0 !== substr_compare($file, $tail, -$len, $len, false)) {
if (method_exists($this->classLoader[0], 'getClassMap')) {
$map = $this->classLoader[0]->getClassMap();
} else {
$map = array();
}

if (! isset($map[$class])) {
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
}
}

break;
}
} while (false !== $i = strpos($tail, '\\'));
} while (false !== $i = strpos($tail, DIRECTORY_SEPARATOR, 1));

if (! $exists) {
if (false !== strpos($class, '/')) {
Expand Down
29 changes: 29 additions & 0 deletions 29 src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ public function testFileCaseMismatch()
{
class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true);
}

/**
* @expectedException \RuntimeException
*/
public function testPsr4CaseMismatch()
{
class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true);
}

public function testNotPsr0()
{
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0', true));
}

public function testNotPsr0Bis()
{
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0bis', true));
}
}

class ClassLoader
Expand All @@ -148,6 +166,11 @@ public function loadClass($class)
{
}

public function getClassMap()
{
return array(__NAMESPACE__.'\Fixtures\NotPSR0bis' => __DIR__ . '/Fixtures/notPsr0Bis.php');
}

public function findFile($class)
{
if (__NAMESPACE__.'\TestingUnsilencing' === $class) {
Expand All @@ -158,6 +181,12 @@ public function findFile($class)
eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}');
} elseif (__NAMESPACE__.'\Fixtures\CaseMismatch' === $class) {
return __DIR__ . '/Fixtures/casemismatch.php';
} elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) {
return __DIR__ . '/Fixtures/psr4/Psr4CaseMismatch.php';
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0' === $class) {
return __DIR__ . '/Fixtures/reallyNotPsr0.php';
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
return __DIR__ . '/Fixtures/notPsr0Bis.php';
}
}
}
7 changes: 7 additions & 0 deletions 7 src/Symfony/Component/Debug/Tests/Fixtures/notPsr0Bis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Debug\Tests\Fixtures;

class NotPSR0bis
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Debug\Tests\Fixtures;

class PSR4CaseMismatch
{
}
7 changes: 7 additions & 0 deletions 7 src/Symfony/Component/Debug/Tests/Fixtures/reallyNotPsr0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Debug\Tests\Fixtures;

class NotPSR0
{
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.