Skip to content

Commit

Permalink
[jan] Fix autoloading using certain locales like Turkish (Bug #13855).
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Apr 16, 2015
1 parent d2b86be commit 57e80a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
20 changes: 18 additions & 2 deletions framework/Autoloader/lib/Horde/Autoloader.php
Expand Up @@ -63,7 +63,7 @@ public function loadClass($className)
{
if (($path = $this->mapToPath($className)) &&
$this->_include($path)) {
$className = strtolower($className);
$className = $this->_lower($className);
if (isset($this->_callbacks[$className])) {
call_user_func($this->_callbacks[$className]);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public function addClassPathMapper(Horde_Autoloader_ClassPathMapper $mapper)
*/
public function addCallback($class, $callback)
{
$this->_callbacks[strtolower($class)] = $callback;
$this->_callbacks[$this->_lower($class)] = $callback;
}

/**
Expand Down Expand Up @@ -140,4 +140,20 @@ protected function _fileExists($path)
return file_exists($path);
}

/**
* Locale independant strtolower() implementation.
*
* @param string $string The string to convert to lowercase.
*
* @return string The lowercased string, based on ASCII encoding.
*/
protected function _lower($string)
{
$language = setlocale(LC_CTYPE, 0);
setlocale(LC_CTYPE, 'C');
$string = strtolower($string);
setlocale(LC_CTYPE, $language);
return $string;
}

}
Expand Up @@ -54,7 +54,7 @@ public function __construct($prefix, $includePath)
*/
public function mapToPath($className)
{
if (stripos($className, $this->_prefix) === 0) {
if ($this->_ipos($className, $this->_prefix) === 0) {
$len = strlen($this->_prefix);
if ($len === strlen($className)) {
return $this->_includePath . '/' . $className . '.php';
Expand All @@ -68,4 +68,21 @@ public function mapToPath($className)
return false;
}

/**
* Locale independant stripos() implementation.
*
* @param string $haystack The string to search through.
* @param string $needle The string to search for.
*
* @return integer The position of first case-insensitive occurrence.
*/
protected function _ipos($haystack, $needle)
{
$language = setlocale(LC_CTYPE, 0);
setlocale(LC_CTYPE, 'C');
$pos = stripos($haystack, $needle);
setlocale(LC_CTYPE, $language);
return $pos;
}

}
4 changes: 2 additions & 2 deletions framework/Autoloader/package.xml
Expand Up @@ -28,7 +28,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix autoloading using certain locales like Turkish (Bug #13855).
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -285,7 +285,7 @@
<date>2014-03-03</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix autoloading using certain locales like Turkish (Bug #13855).
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 57e80a9

Please sign in to comment.