本文整理汇总了PHP中spl_autoload函数的典型用法代码示例。如果您正苦于以下问题:PHP spl_autoload函数的具体用法?PHP spl_autoload怎么用?PHP spl_autoload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spl_autoload函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: helper
public function helper($class)
{
$class = preg_replace('/_helper$/ui', '', $class);
set_include_path(get_include_path() . PATH_SEPARATOR . '/helper/');
spl_autoload_extensions('.helper.php');
spl_autoload($class);
}
示例2: zroneClassLoader
/**
* è‡ªåŠ¨åŠ è½½
*
* @param $className
*/
function zroneClassLoader($className)
{
$path = array(str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Vendor/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "FrameWork/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Application/"));
if (isset($path) && is_array($path)) {
$Iterator = new ArrayIterator($path);
$Iterator->rewind();
$pathString = "";
while ($Iterator->valid()) {
$pathString .= $Iterator->current() . ";";
if ($Iterator->key() == count($path) - 1) {
$pathString = rtrim($pathString, ";");
}
$Iterator->next();
}
set_include_path($pathString);
spl_autoload_extensions(".php, .class.php");
spl_autoload($className);
} else {
try {
throw new Exception("<code style='color: red; font-size: 22px; display: block; text-align: center; height: 40px; line-height: 40px;'>I'm sorry, my dear! The FrameWork is Wrong……😫</code>");
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
示例3: helper
public function helper($class)
{
$class = $this->trim_namespace($class);
set_include_path($this->registry->appDir . '/helpers/');
spl_autoload_extensions('.help.php');
spl_autoload($class);
}
示例4: load
public static function load($class_name)
{
$segments = explode('\\', $class_name);
$class = array_pop($segments);
$file_name = implode('\\', $segments);
// print($file_name);
spl_autoload($file_name, '.php');
}
示例5: autoload
/**
* Load the class specified
* @param string Class to load
*/
function autoload($className)
{
/* We're using the built-in autoloader as it's faster than a PHP implementation.
* Replace underscores with slashes to use a directory structure (FeedSources_Twitter -> includes/FeedSources/Twitter.php)
*/
$filename = strtolower(str_replace('_', '/', $className));
return spl_autoload($filename);
}
示例6: plugin_autoloader
function plugin_autoloader($class)
{
$file = dirname(__FILE__) . '/../../src/class-' . str_replace('_', '-', strtolower($class)) . '.php';
if (file_exists($file)) {
include $file;
} else {
spl_autoload($class);
}
}
示例7: buffered_autoloader
function buffered_autoloader($c)
{
try {
spl_autoload($c);
} catch (Exception $e) {
$message = $e->getMessage();
return $message;
}
}
示例8: register
public static function register($path)
{
if (function_exists('__autoload')) {
spl_autoload_register('__autoload');
}
spl_autoload_register(function ($class) use(&$path) {
set_include_path($path);
spl_autoload($class);
});
}
示例9: base_class
private function base_class($className)
{
$path = array();
$pathDir = array();
$path = explode('_', $className);
$arrCount = count($path) - 1;
$pathDir = implode("/", array_slice($path, 0, $arrCount));
set_include_path(ROOT_PATH . "includes/" . $pathDir);
spl_autoload_extensions('.class.php');
spl_autoload($path[$arrCount]);
}
示例10: registerAutoload
/**
* Register autoloading for classes
*/
public function registerAutoload()
{
// firstly include vendor autoload
include BASEDIR . 'vendor' . DS . 'autoload.php';
// Classes from APPDIR/classes/ directory
set_include_path(get_include_path() . PATH_SEPARATOR . APPDIR . 'classes' . DS);
// all classes from the APPDIR.'classes' directory must have extension '.class.php'
spl_autoload_extensions('.class.php');
// all class files must lowercase name to avoid problems with case sensitivity
spl_autoload_register(function ($class_name) {
spl_autoload(strtolower($class_name));
});
}
示例11: load
private static function load($className) {
foreach(self::$_sources as $path) {
$directories = self::diretoryToArray("./", true);
foreach($directories as $directory) {
if(file_exists($path.'/'.$directory.'/'.$className.'.php')) {
set_include_path($path.'/'.$directory);
spl_autoload($className);
}
}
}
throw new FileNotFoundException();
}
示例12: define
<?php
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
define('LIB', ROOT . '/engine/lib');
define('MODEL_ROOT', ROOT . '/engine/models/');
spl_autoload_extensions('.php');
set_include_path(MODEL_ROOT);
spl_autoload_register(function ($class) {
spl_autoload($class);
});
示例13: spl_autoload
<?php
spl_autoload("Spec");
spl_autoload("Helper");
class AClass extends Automobile
{
const className = "A-Class";
const classPrice = 16000;
const airCondType = "cond";
const airbagSlug = "airbag";
const airBagNumber = 6;
public function __construct()
{
parent::__construct(self::className, self::classPrice);
$this->equipCar();
}
public function equipCar()
{
$specs = SpecStorage::getCommonSpecifications();
array_push($specs, SpecStorage::getSpecification(self::airCondType));
array_push($specs, SpecStorage::getSpecification(self::airbagSlug, self::airBagNumber));
$this->assignDefaultSpecs($specs);
}
}
示例14: autoload
/**
* Autoload function for TYPO3.
*
* This method looks up class names in the registry
* (which contains extensions and core files)
*
* @param string $className Class name
* @return void
*/
public static function autoload($className)
{
$className = ltrim($className, '\\');
$realClassName = static::getClassNameForAlias($className);
$aliasClassName = static::getAliasForClassName($className);
$hasAliasClassName = $aliasClassName !== $className;
$lookUpClassName = ($hasRealClassName = $className !== $realClassName) ? $realClassName : $className;
// Use core and extension registry
$classPath = static::getClassPathByRegistryLookup($lookUpClassName);
if ($classPath && !class_exists($realClassName, FALSE)) {
// Include the required file that holds the class
// Handing over the class name here is only done for the
// compatibility class loader so that it can skip class names
// which do not require rewriting. We can remove this bad
// code smell once we can get rid of the compatibility class loader.
static::requireClassFileOnce($classPath, $className);
try {
// Regular expression for a valid classname taken from
// http://www.php.net/manual/en/language.oop5.basic.php
if (preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $className)) {
spl_autoload($className);
}
} catch (\LogicException $exception) {
}
}
if ($hasRealClassName && !class_exists($className, FALSE)) {
class_alias($realClassName, $className);
}
if ($hasAliasClassName && !class_exists($aliasClassName, FALSE)) {
class_alias($className, $aliasClassName);
}
}
示例15: views
public function views($class)
{
set_include_path(get_include_path() . PATH_SEPARATOR . 'views/');
spl_autoload_extensions('.php');
spl_autoload($class);
}