Giter Site home page Giter Site logo

loader's Introduction

YeahPHP类文件加载器 - ClassLoader

YeahPHP类加载器遵守PSR-4PSR-0命名空间规范,具体使用请看下面介绍

  • 首先加载ClassLoader文件
require "yourpath/src/yeahphp/Loader/ClassLoader.php";
  • 创建一个类加载器对象
$classLoader = new ClassLoader();
  • 添加一个PSR-4命名空间规范的前缀
$classLoader->addPsr4($prefix, $directory);

参数解释

参数名称 说明
$prefix 命名空间前缀
$directory 命名空间前缀对应的路径
  • 添加一个PSR-0命名空间规范的前缀
$classLoader->addPsr0($prefix, $directory);

参数解释

参数名称 说明
$prefix 命名空间前缀
$directory 命名空间前缀对应的路径
  • 添加类的映射
$classLoader->addClassMap($class, $file);

参数解释

参数名称 说明
$class 完整的类名称,包含命名空间
$file 类文件路径
  • 通过classmap文件批量添加类的映射
$classLoader->addClassMapFromFile($file);

参数解释

参数名称 说明
$file classmap文件路径

classmap 文件返回结果为一维数组,格式如下

return array(
    "类名称1" => "类文件路径1",
    "类名称2" => "类文件路径2",
    // ... 
);
  • 注册类自动加载器
$classLoader->register($throw, $prepend);
参数名称 说明
$throw 是否允许抛出异常, 默认为 true
$prepend 是否将加载器添加到队列之首, 默认为false
  • 卸载类自动加载器
$classLoader->unregister();

在项目中,你可以直接加载autolaod文件,该文件已经为您初始化了类加载器和一些基础工作

require "yourpath/src/yeahphp/Loader/autoload.php";

loader's People

Contributors

vnaki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.