Skip to content

Commit 0ae50d9

Browse files
committed
warns on case mismatch
1 parent 9ef6e40 commit 0ae50d9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/RobotLoader/RobotLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public function register($prepend = FALSE)
7777
*/
7878
public function tryLoad($type)
7979
{
80-
$type = ltrim(strtolower($type), '\\'); // PHP namespace bug #49143
80+
$type = $orig = ltrim($type, '\\'); // PHP namespace bug #49143
81+
$type = strtolower($type);
8182

8283
$info = & $this->classes[$type];
8384
if (isset($this->missing[$type]) || (is_int($info) && $info >= self::RETRY_LIMIT)) {
@@ -102,6 +103,9 @@ public function tryLoad($type)
102103
}
103104

104105
if (isset($this->classes[$type]['file'])) {
106+
if ($this->classes[$type]['orig'] !== $orig) {
107+
trigger_error("Case mismatch on class name '$orig', correct name is '{$this->classes[$type]['orig']}'.", E_USER_WARNING);
108+
}
105109
call_user_func(function($file) { require $file; }, $this->classes[$type]['file']);
106110
} else {
107111
$this->missing[$type] = TRUE;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Loaders\RobotLoader case sensitivity.
5+
*/
6+
7+
use Nette\Loaders\RobotLoader,
8+
Nette\Caching\Storages\DevNullStorage,
9+
Tester\Assert;
10+
11+
12+
require __DIR__ . '/../bootstrap.php';
13+
14+
15+
$loader = new RobotLoader;
16+
$loader->setCacheStorage(new DevNullStorage);
17+
$loader->addDirectory(__DIR__ . '/files');
18+
$loader->register();
19+
20+
Assert::error(function(){
21+
Assert::true( class_exists('testClass') );
22+
}, E_USER_WARNING, "Case mismatch on class name 'testClass', correct name is 'TestClass'.");

0 commit comments

Comments
 (0)