diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-30 18:24:46 -0500 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-30 18:24:46 -0500 |
commit | a6df011a107132390ecc35b80ab0e88bc31fd103 (patch) | |
tree | c91b2a90f4c3cef95c1f734aa0b6b0da4007e2ac /phpBB/phpbb/class_loader.php | |
parent | 2ee22d4615a86a33d3c65f94d7a9c4b99dfb1b7e (diff) | |
parent | 179f41475b555d0a3314d779d0d7423f66f0fb95 (diff) | |
download | forums-a6df011a107132390ecc35b80ab0e88bc31fd103.tar forums-a6df011a107132390ecc35b80ab0e88bc31fd103.tar.gz forums-a6df011a107132390ecc35b80ab0e88bc31fd103.tar.bz2 forums-a6df011a107132390ecc35b80ab0e88bc31fd103.tar.xz forums-a6df011a107132390ecc35b80ab0e88bc31fd103.zip |
Merge branch 'develop' of github.com:phpbb/phpbb3 into ticket/11850
# By Nils Adermann (68) and others
# Via Andreas Fischer (12) and others
* 'develop' of github.com:phpbb/phpbb3: (102 commits)
[ticket/11876] Replace MD5 with SHA256.
[ticket/11876] Move checksum generation from build PHP files to phing build.xml
[develop-olympus] Build against 3.0.12 instead of 3.0.12-RC3. Tag exists now.
[prep-release-3.0.12] Update changelog for 3.0.12 release.
[ticket/11873] Add unit test for large password input.
[ticket/11873] Do not hash very large passwords in order to safe resources.
[ticket/11862] Correct var names in user_delete() events due to prune-users
[develop-olympus] Use 3.0.13-dev as build version. Use latest 3.0.12 RC tag.
[prep-release-3.0.12] Bumping version number for 3.0.12 final.
[ticket/11852] Add class file
[ticket/11852] Move tests to folder with new class name
[ticket/11852] Split filesystem and path_helper into 2 classes
[ticket/11868] Add @depends to test
[ticket/11868] Add functional test for registration
[ticket/11868] Replace phpbb_request_interface references
[ticket/11866] Only single backslash in .md files
[ticket/11866] Remove outdated and broken develop script
[ticket/11866] More namespaces
[ticket/11866] Update some occurances of phpbb_db_ to new Namespace
[ticket/11865] Convert old class name to namespaced version
...
Conflicts:
tests/security/extract_current_page_test.php
tests/session/testable_facade.php
Diffstat (limited to 'phpBB/phpbb/class_loader.php')
-rw-r--r-- | phpBB/phpbb/class_loader.php | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/phpBB/phpbb/class_loader.php b/phpBB/phpbb/class_loader.php index 02a2d584dc..769f28b4f1 100644 --- a/phpBB/phpbb/class_loader.php +++ b/phpBB/phpbb/class_loader.php @@ -7,6 +7,8 @@ * */ +namespace phpbb; + /** * @ignore */ @@ -28,9 +30,9 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_class_loader +class class_loader { - private $prefix; + private $namespace; private $path; private $php_ext; private $cache; @@ -44,17 +46,22 @@ class phpbb_class_loader private $cached_paths = array(); /** - * Creates a new phpbb_class_loader, which loads files with the given + * Creates a new \phpbb\class_loader, which loads files with the given * file extension from the given path. * - * @param string $prefix Required class name prefix for files to be loaded + * @param string $namespace Required namespace for files to be loaded * @param string $path Directory to load files from * @param string $php_ext The file extension for PHP files - * @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface. + * @param \phpbb\cache\driver\driver_interface $cache An implementation of the phpBB cache interface. */ - public function __construct($prefix, $path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null) - { - $this->prefix = $prefix; + public function __construct($namespace, $path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null) + { + if ($namespace[0] !== '\\') + { + $namespace = '\\' . $namespace; + } + + $this->namespace = $namespace; $this->path = $path; $this->php_ext = $php_ext; @@ -66,13 +73,13 @@ class phpbb_class_loader * the class loader will resolve paths by checking for the existance of every * directory in the class name every time. * - * @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface. + * @param \phpbb\cache\driver\driver_interface $cache An implementation of the phpBB cache interface. */ - public function set_cache(phpbb_cache_driver_interface $cache = null) + public function set_cache(\phpbb\cache\driver\driver_interface $cache = null) { if ($cache) { - $this->cached_paths = $cache->get('class_loader_' . $this->prefix); + $this->cached_paths = $cache->get('class_loader_' . str_replace('\\', '__', $this->namespace)); if ($this->cached_paths === false) { @@ -102,8 +109,9 @@ class phpbb_class_loader /** * Resolves a phpBB class name to a relative path which can be included. * - * @param string $class The class name to resolve, must have a phpbb_ - * prefix + * @param string $class The class name to resolve, must be in the + * namespace the loader was constructed with. + * Has to begin with \ * @return string|bool A relative path to the file containing the * class or false if looking it up failed. */ @@ -114,27 +122,12 @@ class phpbb_class_loader return $this->path . $this->cached_paths[$class] . '.' . $this->php_ext; } - if (!preg_match('/^' . $this->prefix . '[a-zA-Z0-9_]+$/', $class)) + if (!preg_match('/^' . preg_quote($this->namespace, '/') . '[a-zA-Z0-9_\\\\]+$/', $class)) { return false; } - $parts = explode('_', substr($class, strlen($this->prefix))); - - $dirs = ''; - - for ($i = 0, $n = sizeof($parts); $i < $n && is_dir($this->path . $dirs . $parts[$i]); $i++) - { - $dirs .= $parts[$i] . '/'; - } - - // no file name left => use last dir name as file name - if ($i == sizeof($parts)) - { - $parts[] = $parts[$i - 1]; - } - - $relative_path = $dirs . implode(array_slice($parts, $i, sizeof($parts) - $i), '_'); + $relative_path = str_replace('\\', '/', substr($class, strlen($this->namespace))); if (!file_exists($this->path . $relative_path . '.' . $this->php_ext)) { @@ -144,7 +137,7 @@ class phpbb_class_loader if ($this->cache) { $this->cached_paths[$class] = $relative_path; - $this->cache->put('class_loader_' . $this->prefix, $this->cached_paths); + $this->cache->put('class_loader_' . str_replace('\\', '__', $this->namespace), $this->cached_paths); } return $this->path . $relative_path . '.' . $this->php_ext; @@ -157,7 +150,8 @@ class phpbb_class_loader */ public function load_class($class) { - if (substr($class, 0, strlen($this->prefix)) === $this->prefix) + $class = '\\' . $class; + if (substr($class, 0, strlen($this->namespace)) === $this->namespace) { $path = $this->resolve_path($class); |