承接 joefallon/phpautoloader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joefallon/phpautoloader

Composer 安装命令:

composer require joefallon/phpautoloader

包简介

Joe's simple to use and versatile PHP autoloader.

README 文档

README

By Joe Fallon

Joe's PHP Autoloader is a versatile and easy to use autoloader for PHP 5.3 and greater. It provides the following features:

  • When auto-loading a class, all of the include paths are searched automatically.
  • For maximum legacy support, non-namespaced classes are allowed.
  • Normal PSR-0 namespaced classes are supported.
  • Underscore namespaced (e.g. like the Zend Framework 1 or PEAR) classes are supported.
  • This autoloader is fast. No recursive directory searches are performed.

Requirements

The only requirement is PHP > 5.3.0. This is due to the use of namespaces. Additionally, Composer can be helpful.

Installation

The easiest way to install Joe's Autoloader is with Composer. Create the following composer.json file and run the php composer.phar install command to install it.

{
    "require": {
        "joefallon/phpautoloader": "*"
    }
}

Usage

To use Joe's Autoloader, the following initialization steps are needed:

  • Add the base directories where classes can be found to the include path.
  • Call the Autoloader::registerAutoload() method to load the autoloader.
  • Start using classes in your code.
use JoeFallon\AutoLoader;

// Define the include paths.
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('LIB_PATH',  BASE_PATH . '/lib');
define('VEND_PATH', BASE_PATH . '/vendor');

// Set the application include paths for auto-loading.
set_include_path(get_include_path() . ':' . LIB_PATH . ':' . BASE_PATH);

// Require the Composer autoloader. Composer will handle its own class auto-loading
// using its own autoloader.
require(VEND_PATH . '/autoload.php');

// Initialize Joe's Autoloader. Joe's Autoloader will handle auto-loading any classes
// that are not auto-loaded using Composer's built-in autoloader.
Autoloader::registerAutoLoad();

As long as namespaces are mapped to the folder structure within the directories defined above, then autoloader will have no problems finding and loading the classes.

For example, let's assume we want to load the class Bar that is within the file named Bar.php contained within a folder Foo. Also, let's assume that the class Bar is namespaced \Foo\Bar. This would give a file path of LIB_PATH/Foo/Bar.php. When new Bar(); is executed, the Bar class will be loaded (if is was not already).

Here is a visual depiction of the above example:

Joe's Autoloader Example

统计信息

  • 总下载量: 401
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固