awps/loader

一个简单的加载器,旨在与类和普通PHP文件一起工作。

1.0.1 2017-12-18 22:47 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:49:11 UTC


README

加载器

一个简单的加载器,旨在与类和普通PHP文件一起工作。

安装

使用composer

composer require awps/loader

手动安装

require_once 'getloader.php';

使用方法

加载PHP类

Awps\Loader::loadClasses( $path, $namespace );

这将自动加载来自$path的所有PHP类,并假定这些类的命名空间为$namespace;

加载简单PHP文件

Awps\Loader::loadFiles( $path, $pattern );

这将自动加载来自$path的所有包含$pattern名称模式的PHP文件。

示例

// Autoload classes from `inc` folder and set the namespace to `Awesome`
Awps\Loader::loadClasses( __DIR__ . 'inc', 'Awesome' );

// Now you can initialize a class. For example: 
new Awesome\Something();

// -------------------------------------------------------

// Include all php files from `functions`
Awps\Loader::loadFiles( __DIR__ . 'functions', 'component-' );

// This one will include all php files that contains `component-` string in their name
// from `functions` directory.
// Now you may call a function defined in one of those files. For example: 
do_something_special();