Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing underscores from the GenericLoader properties.

  • Loading branch information...
commit 5fd013e13bcada33f69babcaa052d97f005b159d 1 parent 3624e12
@zyxist zyxist authored
View
50 src/Opl/Autoloader/GenericLoader.php
@@ -28,25 +28,25 @@ class GenericLoader
* @static
* @var string
*/
- private $_defaultPath = '';
+ private $defaultPath = '';
/**
* The list of available top-level namespaces.
* @var array
*/
- private $_namespaces = array();
+ private $namespaces = array();
/**
* The file extensions in the namespaces.
* @var array
*/
- private $_extensions = array();
+ private $extensions = array();
/**
* The namespace separator
* @var string
*/
- private $_namespaceSeparator = '\\';
+ private $namespaceSeparator = '\\';
/**
* Constructs the autoloader.
@@ -56,14 +56,14 @@ class GenericLoader
*/
public function __construct($defaultPath = './', $namespaceSeparator = '\\')
{
- $this->_namespaceSeparator = $namespaceSeparator;
+ $this->namespaceSeparator = $namespaceSeparator;
$length = strlen($defaultPath);
if($length == 0 || $defaultPath[$length - 1] != '/')
{
$defaultPath .= '/';
}
- $this->_defaultPath = $defaultPath;
+ $this->defaultPath = $defaultPath;
} // end __construct();
/**
@@ -75,7 +75,7 @@ public function __construct($defaultPath = './', $namespaceSeparator = '\\')
*/
public function addNamespace($namespace, $path = null, $extension = '.php')
{
- if(isset($this->_namespaces[(string)$namespace]))
+ if(isset($this->namespaces[(string)$namespace]))
{
throw new DomainException('The namespace '.$namespace.' is already added.');
}
@@ -86,13 +86,13 @@ public function addNamespace($namespace, $path = null, $extension = '.php')
{
$path .= '/';
}
- $this->_namespaces[(string)$namespace] = $path;
+ $this->namespaces[(string)$namespace] = $path;
}
else
{
- $this->_namespaces[(string)$namespace] = $this->_defaultPath;
+ $this->namespaces[(string)$namespace] = $this->defaultPath;
}
- $this->_extensions[(string)$namespace] = $extension;
+ $this->extensions[(string)$namespace] = $extension;
} // end addNamespace();
/**
@@ -102,7 +102,7 @@ public function addNamespace($namespace, $path = null, $extension = '.php')
*/
public function hasNamespace($namespace)
{
- return isset($this->_namespaces[(string)$namespace]);
+ return isset($this->namespaces[(string)$namespace]);
} // end hasNamespace();
/**
@@ -112,12 +112,12 @@ public function hasNamespace($namespace)
*/
public function removeNamespace($namespace)
{
- if(!isset($this->_namespaces[(string)$namespace]))
+ if(!isset($this->namespaces[(string)$namespace]))
{
throw new DomainException('The namespace '.$namespace.' is not available.');
}
- unset($this->_namespaces[(string)$namespace]);
- unset($this->_extensions[(string)$namespace]);
+ unset($this->namespaces[(string)$namespace]);
+ unset($this->extensions[(string)$namespace]);
} // end removeNamespace();
/**
@@ -127,7 +127,7 @@ public function removeNamespace($namespace)
*/
public function setNamespaceSeparator($sep)
{
- $this->_namespaceSeparator = $sep;
+ $this->namespaceSeparator = $sep;
} // end setNamespaceSeparator();
/**
@@ -137,7 +137,7 @@ public function setNamespaceSeparator($sep)
*/
public function getNamespaceSeparator()
{
- return $this->_namespaceSeparator;
+ return $this->namespaceSeparator;
} // end getNamespaceSeparator();
/**
@@ -152,7 +152,7 @@ public function setDefaultPath($defaultPath)
{
$defaultPath .= '/';
}
- $this->_defaultPath = $defaultPath;
+ $this->defaultPath = $defaultPath;
} // end setDefaultPath();
/**
@@ -162,7 +162,7 @@ public function setDefaultPath($defaultPath)
*/
public function getDefaultPath()
{
- return $this->_defaultPath;
+ return $this->defaultPath;
} // end getDefaultPath();
/**
@@ -189,19 +189,19 @@ public function unregister()
*/
public function loadClass($className)
{
- $className = ltrim($className, $this->_namespaceSeparator);
- $match = strstr($className, $this->_namespaceSeparator, true);
+ $className = ltrim($className, $this->namespaceSeparator);
+ $match = strstr($className, $this->namespaceSeparator, true);
- if(false === $match || !isset($this->_namespaces[$match]))
+ if(false === $match || !isset($this->namespaces[$match]))
{
return false;
}
- $rest = strrchr($className, $this->_namespaceSeparator);
+ $rest = strrchr($className, $this->namespaceSeparator);
$replacement =
- str_replace($this->_namespaceSeparator, '/', substr($className, 0, strlen($className) - strlen($rest))).
- str_replace(array('_', $this->_namespaceSeparator), '/', $rest);
+ str_replace($this->namespaceSeparator, '/', substr($className, 0, strlen($className) - strlen($rest))).
+ str_replace(array('_', $this->namespaceSeparator), '/', $rest);
- require($this->_namespaces[$match].$replacement.$this->_extensions[$match]);
+ require($this->namespaces[$match].$replacement.$this->extensions[$match]);
return true;
} // end loadClass();
} // end GenericLoader;
View
12 tests/TestSuite/GenericLoaderTest.php
@@ -87,9 +87,9 @@ public function testAddNamespaceSetsDefaultPathAndExtension()
$loader->addNamespace('Foo');
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
- $extensionsProperty = $reflection->getProperty('_extensions');
+ $extensionsProperty = $reflection->getProperty('extensions');
$extensionsProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './foo/bar/'), $namespacesProperty->getValue($loader));
@@ -102,9 +102,9 @@ public function testAddNamespaceSetsCustomPathAndExtension()
$loader->addNamespace('Foo', './bar/joe/', '.php5');
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
- $extensionsProperty = $reflection->getProperty('_extensions');
+ $extensionsProperty = $reflection->getProperty('extensions');
$extensionsProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './bar/joe/'), $namespacesProperty->getValue($loader));
@@ -129,9 +129,9 @@ public function testRemoveNamespace()
$this->assertTrue($loader->hasNamespace('Foo'));
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
- $extensionsProperty = $reflection->getProperty('_extensions');
+ $extensionsProperty = $reflection->getProperty('extensions');
$extensionsProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './foo/bar/'), $namespacesProperty->getValue($loader));
Please sign in to comment.
Something went wrong with that request. Please try again.