5 Star 7 Fork 6

阿债 / pram-locator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

\Pram\Locator

A class loader for PSR-0-style class loading. Same as Symfony Class Loader.

一个用于PHP自动加载的类,作用与Symfony中的Class Loader相同。

在我常用的一些PHP库中测试都没有问题,包括

  • ApnsPHP
  • ConsoleKit
  • Guzzle
  • NotORM
  • React
  • Requests
  • SwiftMailer
  • Symfony
  • Twig
  • Yaml
  • Zf/Zf2

它们中既有如Zf2一样使用namespace的,也有Zf一样使用_分割的长类名。

其中不少自带Autoload,或者使用composer,但您完全可以用\Pram\Locator代替它们。

使用方法

    <?php
    defined(VENDOR_ROOT) define(VENDOR_ROOT, __DIR__ . '/pram3/vendor');
    //先将这个类包含进来,创建单例,同时它将注册到PHP系统中
    require_once __DIR__ . '/pram3/src/Pram/Locator.php';
    $locator = \Pram\Locator::getInstance();
    //注册namespace前缀所在目录
    $locator->addNamespace('NotORM', VENDOR_ROOT . '/NotORM');
    //或者注册类入口的文件
    $locator->addClass(VENDOR_ROOT . '/NotORM/NotORM.php',
        'NotORM', 'NotORM_Result', 'NotORM_Row', 'NotORM_Literal', 'NotORM_Structure');
    //复杂的用法,React就是这朵奇葩,把Promise当作自己的子Namespace使用
    $locator->addNamespace('React', array(
        '.' => VENDOR_ROOT . '/React/src',
        'Promise' => VENDOR_ROOT . '/Promise/src/React',
    ));
    $locator->addNamespace('Guzzle', VENDOR_ROOT . '/Guzzle/src');
    $locator->addNamespace('Evenement', VENDOR_ROOT . '/Evenement/src');
The MIT License (MIT) Copyright (c) 2013 Ryan Liu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个用于PHP自动加载的类,作用与Symfony中的Class Loader相同。 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/azhai/pram-locator.git
git@gitee.com:azhai/pram-locator.git
azhai
pram-locator
pram-locator
master

搜索帮助