定制 popphp/pop-loader 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

popphp/pop-loader

最新稳定版本:3.1.1

Composer 安装命令:

composer require popphp/pop-loader

包简介

Pop Loader Component for Pop PHP Framework

README 文档

README

Build Status Coverage Status

OVERVIEW

pop-loader is a component for managing the autoloading of an application. If, for some reason you do not or cannot use Composer, pop-loader provides an alternative with similar features and API. It supports both PSR-4 and PSR-0 autoloading standards. Additionally, there is support for generating and loading class maps, if you are interested in boosting the speed and performance of your application's load times.

pop-loader is a component of the Pop PHP Framework.

INSTALL

Download or clone this repository and follow the examples below to wire up the autoloading required by your application. Or, you can install pop-loader using Composer - ironic, I know :)

composer require popphp/pop-loader

BASIC USAGE

Using PSR-4

Let's say your app contains a src folder with a Test class in it like this:

app/
    src/
        Test.php
<?php
namespace MyApp;

class Test
{

}

Then, you can create an autoloader object and register your application's source with it like this:

require_once __DIR__ . '/../src/ClassLoader.php';

$autoloader = new Pop\Loader\ClassLoader();
$autoloader->addPsr4('MyApp\\', __DIR__ . '/../app/src');

$test = new MyApp\Test();

Using PSR-0

There's also support for older the PSR-0 standard. If the folder structure and class was like this:

app/
    MyApp/
        Test.php
<?php
class MyApp_Test
{

}

Then, you can register it using PSR-0 like this:

require_once __DIR__ . '/../src/ClassLoader.php';

$autoloader = new Pop\Loader\ClassLoader();
$autoloader->addPsr0('MyApp', __DIR__ . '/../app');

$test = new MyApp_Test();

Using a class map

To generate a new class map:

$mapper = new Pop\Loader\ClassMapper(__DIR__ . '/../app/src');
$mapper->writeToFile('classmap.php');
classmap.php
<?php

return [
    'MyApp\Foo\Bar' => '/home/nick/Projects/pop/pop-loader/app/src/Foo/Bar.php',
    'MyApp\Thing' => '/home/nick/Projects/pop/pop-loader/app/src/Thing.php',
    'MyApp\Test' => '/home/nick/Projects/pop/pop-loader/app/src/Test.php'
];

To load an existing class map:

$autoloader = new Pop\Loader\ClassLoader();
$autoloader->addClassMapFromFile('classmap.php');

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-11