tuum/builder
Composer 安装命令:
composer require tuum/builder
包简介
a generic builder for PHP application based on environment.
README 文档
README
A generic builder for application construction based on various server environment.
Licence
MIT License
PSR
PSR-1, PSR-2, and PSR-4.
Installation
composer require "tuum/builder: ^1.0.0"
Sample Code
use WScore\Builder\Builder; $builder = Builder::forge( __DIR__ . '/config, // app directory __DIR__ . '/var', // var directory true // debug ); $builder->loadEnv(); $builder->load('setup'); $builder->load('routes'); if ($builder->isEnv('local')) { $builder->load('extra.local'); } $app = $builder->getApp(); // <- must set an app using setApp()!
Basic Usage
Directory Structure
Tuum/Builder assumes there are two directories to build an application:
APP_DIR: directory for application settings, andVAR_DIR: directory for files not under version control.
For instance,
+ config/ // <- APP_DIR
+ setup.php
+ routes.php
+ var/ // <- VAR_DIR
+ .env
+ cache/
Construction
Construct the application builder with two directories:
use WScore\Builder\Builder; $builder = new Builder([ Builder::APP_DIR => __DIR__ . '/config, // app directory Builder::VAR_DIR => __DIR__ . '/var', // var directory Builder::DEBUG => true // debug ]);
Or, simply use forge method as shown in the Sample Code Section.
Loading PHP File
To load configuration files under the APP_DIR, use load method as;
$builder->load('setup');
In setup.php file, set up the application, such as:
/** @var Tuum\Builder\Builder $builder */ $builder->set(Builder::APP_KEY, 'ENV'); // set value $builder->setApp(new YourApp()); // set your application return [ 'db-name' => $builder->get('DB_NAME', 'demo'), ]; // may return some value
- The builder has
has,get, andsetmethods as expected. - There are
setApp()andgetApp()methods to store your application. - The returned value from the PHP files are stored in the builder
using its load name, which can be accessed by:
$builder->get('setup');.
Getting Values
The get method tries to get value from:
- environment value,
$builder's internal value- default value.
$builder->get('DB_NAME', 'my_db');
Environment File
Loads .env file using vlucas's dotenv component.
The default location of the .env file is at VAR_DIR.
The .env file contains APP_ENV key to specify the environment as such;
APP_ENV = local
Then, you can access the environment as,
$builder->loadEnv(); // load the .env file $builder->isEnv('local'); $builder->isEnvProd(); $env = $builder->getEnv();
The builder considers the environment as prod
if no environment is set, or no environment file to load.
To change the key string used to specify the environment,
set Builder::APP_KEY value to the new key name, such as;
$builder->set(Builder::APP_KEY, 'ENV'); // set value
tuum/builder 适用场景与选型建议
tuum/builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tuum/builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tuum/builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-07