Permalink
Browse files

Merge branch 'develop' into feature-universalloader

  • Loading branch information...
2 parents f9f22b1 + 27c4e49 commit b86badcfccf7444c49dc066c8e9ef2528cf5de4f @zyxist zyxist committed Jun 14, 2011
@@ -29,26 +29,26 @@ class ClassMapLoader
* @static
* @var string
*/
- private $_defaultPath = '';
+ private $defaultPath = '';
/**
* The list of available top-level namespaces.
* @var array
*/
- private $_namespaces = array();
+ private $namespaces = array();
/**
* The loaded class map.
* @var array
* @internal
*/
- protected $_classMap;
+ protected $classMap;
/**
* The location where the class map is stored.
* @var string
* @internal
*/
- protected $_classMapLocation;
+ protected $classMapLocation;
/**
* Creates the class map loader and loads the map into the memory.
@@ -61,15 +61,15 @@ class ClassMapLoader
public function __construct($defaultPath, $classMapLocation, Cache $cache = null)
{
$this->setDefaultPath($defaultPath);
- $this->_classMapLocation = $classMapLocation;
+ $this->classMapLocation = $classMapLocation;
if(null !== $cache)
{
- $this->_classMap = $cache->get('classMap');
- if(null === $this->_classMap)
+ $this->classMap = $cache->get('classMap');
+ if(null === $this->classMap)
{
$this->_loadMap();
- $cache->set('classMap', $this->_classMap);
+ $cache->set('classMap', $this->classMap);
}
}
else
@@ -86,13 +86,13 @@ public function __construct($defaultPath, $classMapLocation, Cache $cache = null
*/
protected function _loadMap()
{
- if(!file_exists($this->_classMapLocation))
+ if(!file_exists($this->classMapLocation))
{
throw new RuntimeException('Cannot find a class map under the specified location.');
}
- $this->_classMap = unserialize(file_get_contents($this->_classMapLocation));
+ $this->classMap = unserialize(file_get_contents($this->classMapLocation));
- if(!is_array($this->_classMap))
+ if(!is_array($this->classMap))
{
throw new RuntimeException('The loaded file does not contain a valid class map.');
}
@@ -108,7 +108,7 @@ protected function _loadMap()
*/
public function addNamespace($namespace, $path = null)
{
- if(isset($this->_namespaces[(string)$namespace]))
+ if(isset($this->namespaces[(string)$namespace]))
{
throw new RuntimeException('The namespace '.$namespace.' is already added.');
}
@@ -119,11 +119,11 @@ public function addNamespace($namespace, $path = null)
{
$path .= '/';
}
- $this->_namespaces[(string)$namespace] = $path;
+ $this->namespaces[(string)$namespace] = $path;
}
else
{
- $this->_namespaces[(string)$namespace] = $this->_defaultPath;
+ $this->namespaces[(string)$namespace] = $this->defaultPath;
}
} // end addNamespace();
@@ -134,7 +134,7 @@ public function addNamespace($namespace, $path = null)
*/
public function hasNamespace($namespace)
{
- return isset($this->_namespaces[(string)$namespace]);
+ return isset($this->namespaces[(string)$namespace]);
} // end hasNamespace();
/**
@@ -145,11 +145,11 @@ public function hasNamespace($namespace)
*/
public function removeNamespace($namespace)
{
- if(!isset($this->_namespaces[(string)$namespace]))
+ if(!isset($this->namespaces[(string)$namespace]))
{
throw new RuntimeException('The namespace '.$namespace.' is not available.');
}
- unset($this->_namespaces[(string)$namespace]);
+ unset($this->namespaces[(string)$namespace]);
} // end removeNamespace();
/**
@@ -165,7 +165,7 @@ public function setDefaultPath($defaultPath)
{
$defaultPath .= '/';
}
- $this->_defaultPath = $defaultPath;
+ $this->defaultPath = $defaultPath;
} // end setDefaultPath();
/**
@@ -175,7 +175,7 @@ public function setDefaultPath($defaultPath)
*/
public function getDefaultPath()
{
- return $this->_defaultPath;
+ return $this->defaultPath;
} // end getDefaultPath();
/**
@@ -185,7 +185,7 @@ public function getDefaultPath()
*/
public function getClassMapLocation()
{
- return $this->_classMapLocation;
+ return $this->classMapLocation;
} // end getClassMapLocation();
/**
@@ -212,11 +212,11 @@ public function unregister()
*/
public function loadClass($className)
{
- if(!isset($this->_classMap[$className]))
+ if(!isset($this->classMap[$className]))
{
return false;
}
- require($this->_namespaces[$this->_classMap[$className][0]].$this->_classMap[$className][1]);
+ require($this->namespaces[$this->classMap[$className][0]].$this->classMap[$className][1]);
return true;
} // end loadClass();
} // end ClassMapLoader;
@@ -10,7 +10,7 @@
* and other contributors. See website for details.
*/
namespace Opl\Autoloader;
-use RuntimeException;
+use DomainException;
/**
* The generic class autoloader is a slightly enhanced version of the
@@ -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,9 +75,9 @@ 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 RuntimeException('The namespace '.$namespace.' is already added.');
+ throw new DomainException('The namespace '.$namespace.' is already added.');
}
if($path !== null)
{
@@ -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 RuntimeException('The namespace '.$namespace.' is not available.');
+ 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;
@@ -26,7 +26,7 @@ class PHARLoader
* @var array
* @internal
*/
- protected $_classMap;
+ protected $classMap;
/**
* Creates the class map loader and loads the map into the memory.
@@ -37,7 +37,7 @@ class PHARLoader
*/
public function __construct(array $classMap)
{
- $this->_classMap = $classMap;
+ $this->classMap = $classMap;
} // end __construct();
/**
@@ -64,11 +64,11 @@ public function unregister()
*/
public function loadClass($className)
{
- if(!isset($this->_classMap[$className]))
+ if(!isset($this->classMap[$className]))
{
return false;
}
- require('phar://'.__FILE__.'/'.$this->_classMap[$className][1]);
+ require('phar://'.__FILE__.'/'.$this->classMap[$className][1]);
return true;
} // end loadClass();
} // end PHARLoader;
@@ -77,7 +77,7 @@ public function testAddNamespaceSetsDefaultPath()
$loader->addNamespace('Foo');
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './foo/bar/'), $namespacesProperty->getValue($loader));
@@ -89,7 +89,7 @@ public function testAddNamespaceSetsCustomPath()
$loader->addNamespace('Foo', './bar/joe/');
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './bar/joe/'), $namespacesProperty->getValue($loader));
@@ -113,7 +113,7 @@ public function testRemoveNamespace()
$this->assertTrue($loader->hasNamespace('Foo'));
$reflection = new \ReflectionObject($loader);
- $namespacesProperty = $reflection->getProperty('_namespaces');
+ $namespacesProperty = $reflection->getProperty('namespaces');
$namespacesProperty->setAccessible(true);
$this->assertEquals(array('Foo' => './foo/bar/'), $namespacesProperty->getValue($loader));
Oops, something went wrong.

0 comments on commit b86badc

Please sign in to comment.