Enhances Zend_Loader to provide a package registry and auto-loading of 'special' module classes such as: controllers, forms, models, etc.
More...
List of all members.
Static Public Member Functions |
static | addPackagePath ($namespace, $path) |
| Register a module path to be checked when auto-loading classes.
|
static | autoload ($class) |
| Load classes via package registry and with knowledge of 'special' module classes such as: controllers, forms, models, etc.
|
static | getPackagePaths () |
| Get the set of registered module paths.
|
static | setPackagePaths ($paths) |
| Set module paths to the given array of paths keyed on namespaces.
|
Static Protected Member Functions |
static | _resolveSpecialClass ($class, $package) |
| Find the path to a special class that resides in a registered package.
|
static | _securityCheck ($filename) |
| Ensure that filename does not contain exploits.
|
Static Protected Attributes |
static | $_packages = array() |
Detailed Description
Enhances Zend_Loader to provide a package registry and auto-loading of 'special' module classes such as: controllers, forms, models, etc.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Member Function Documentation
static P4Cms_Loader::_resolveSpecialClass |
( |
$ |
class, |
|
|
$ |
package |
|
) |
| [static, protected] |
Find the path to a special class that resides in a registered package.
- Parameters:
-
string | $class | the name of the class to resolve. |
string | $package | the name of the package. |
- Returns:
- false|string the path to the class, or false if unsuccessful.
{
$classTypes = array(
"Acl" => "acls",
"Acl_Assert" => "acls/asserts",
"Controller_Helper" => "controllers/helpers",
"Filter" => "filters",
"Form" => "forms",
"Form_Decorator" => "forms/decorators",
"Form_Element" => "forms/elements",
"Model" => "models",
"Test" => "tests",
"Validate" => "validators",
"View_Helper" => "views/helpers"
);
$suffix = substr($class, strrpos($class, '_') + 1);
$prefix = substr($class, strpos($class, '_') + 1, -(strlen($suffix) + 1));
if (!$prefix && substr($suffix, -10) === "Controller") {
$path = "controllers/" . $suffix;
} else if (isset($classTypes[$prefix])) {
$path = $classTypes[$prefix] . '/' . $suffix;
} else {
return false;
}
$file = static::$_packages[$package] . '/' . $path . ".php";
if (is_readable($file)) {
return $file;
} else {
return false;
}
}
static P4Cms_Loader::_securityCheck |
( |
$ |
filename | ) |
[static, protected] |
Ensure that filename does not contain exploits.
- Parameters:
-
string | $filename | the filename to check for exploits |
- Returns:
- void
- Exceptions:
-
Zend_Exception | if the filename contains illegal characters |
{
if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception('Security check: Illegal character in filename');
}
}
static P4Cms_Loader::addPackagePath |
( |
$ |
namespace, |
|
|
$ |
path |
|
) |
| [static] |
Register a module path to be checked when auto-loading classes.
- Parameters:
-
string | $namespace | the module namespace. |
string | $path | the absolute path to the module. |
{
self::$_packages[$namespace] = $path;
}
static P4Cms_Loader::autoload |
( |
$ |
class | ) |
[static] |
Load classes via package registry and with knowledge of 'special' module classes such as: controllers, forms, models, etc.
- Parameters:
-
string | $class | the name of the class to load. |
- Returns:
- string|false class name on success - false on failure
{
$package = substr($class, 0, strpos($class, '_'));
if (isset(static::$_packages[$package])) {
$file = static::$_packages[$package] . '/'
. str_replace('_', '/', substr($class, strlen($package) + 1))
. '.php';
if (is_readable($file)
|| $file = static::_resolveSpecialClass($class, $package)
) {
include $file;
return $class;
}
}
$file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
self::_securityCheck($file);
if (Zend_Loader::isReadable($file)) {
include $file;
return $class;
}
return false;
}
static P4Cms_Loader::getPackagePaths |
( |
| ) |
[static] |
Get the set of registered module paths.
- Returns:
- array an array of registered module paths keyed on namespaces.
static P4Cms_Loader::setPackagePaths |
( |
$ |
paths | ) |
[static] |
Set module paths to the given array of paths keyed on namespaces.
- Parameters:
-
array | $paths | an array of module paths keyed on namespaces. |
{
self::$_packages = $paths;
}
Member Data Documentation
P4Cms_Loader::$_packages = array() [static, protected] |
The documentation for this class was generated from the following file: