lithemod / import
该软件包最新版本(v1.0.0)没有可用的许可信息。
支持动态包含PHP文件和管理外部变量。
v1.0.0
2024-10-02 15:36 UTC
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2024-10-02 15:38:33 UTC
README
Lite Import是一个PHP库,旨在简化PHP文件的动态包含和外部变量的管理。
安装
您可以使用Composer安装Import
。在终端中运行以下命令
composer require lithemod/import
用法
包含单个文件
要包含单个PHP文件,请使用file
方法
use Lithe\Support\import; $result = import::file('path/to/your/testfile.php');
包含目录中的所有文件
要包含指定目录(及其子目录)中的所有PHP文件,您可以设置目录并调用get
方法
use Lithe\Support\import; $importer = import::dir('path/to/directory')->exceptions(['exclude.php']); $importer->get();
使用外部变量
您可以指定应在包含的文件中可用的外部变量
use Lithe\Support\import; $vars = ['var1' => 'value1']; import::with($vars)->dir('path/to/directory')->get();
排除文件
要排除特定文件不被包含,请使用exceptions
方法
$importer = import::dir('path/to/directory')->exceptions(['exclude.php']); $importer->get();
方法概述
with(array $vars)
:设置在包含的文件中可用的外部变量。dir(string $directory)
:设置文件包含的目录。exceptions(array $exceptions)
:指定要排除的文件。file(string $file)
:包含单个PHP文件并返回其结果。get()
:包含指定目录中的所有PHP文件,排除指定的异常。
许可
本项目采用MIT许可证。有关详细信息,请参阅LICENSE文件。