zofe / deficient
laravel组件的实验性子集
1.0.15
2014-10-31 23:12 UTC
Requires
- php: >=5.3.2
- illuminate/cache: 4.1.*
- illuminate/config: 4.1.*
- illuminate/database: 4.1.*
- illuminate/events: 4.1.*
- illuminate/support: 4.1.*
- illuminate/translation: 4.1.*
- illuminate/validation: 4.1.*
- philo/laravel-blade: 1.*
- zofe/burp: 1.0.*
README
Deficient提供了部分laravel组件,而不包含整个环境。
您也可以添加一些其他包,因为我保留了IOC和服务提供者的启动。
它还有一些辅助工具,以保持简洁的语法。
基本上您将获得
- eloquent
- 验证
- 翻译
- blade
- burp(一个微小、非阻塞的路由器)
为什么
在某些情况下,对于大型项目,您不能一开始就切换到Laravel,您需要逐步、分部分地进行迁移。在另一些情况下,您可能只需要一个优秀的ORM,或者/和模板引擎,或者表单验证,翻译等,但不需要“框架”。
将“deficient”视为一种使用laravel的方式,而不需要迁移到laravel,或者(更好)一种缓慢而安静地拥抱laravel的方式,在每个组件中,在您喜欢的位置和时间,以您喜欢的方式。
另一方面
- deficient使vendor大小为3.5 mb
- laravel构建的vendor大小为20 mb
(使用4.1版本的illuminate组件--prefer-dist版本,两者都是)
安装
通过composer创建或添加依赖到您的composer.json中安装
{
"require": {
"zofe/deficient": "dev-master"
}
}
然后运行composer install
使用
您可以设置一个基本的文件结构,以存储配置、视图、语言文件和模型。
建议的一个是
/config
app.php
database.php
/lang
/en
validation.php
/models
User.php
/cache
/views
hello.blade.php
要创建此结构,您可以简单地运行一个设置命令
(重要:确保您当前应用程序中没有与文件夹冲突的文件夹)
php vendor/zofe/deficient/deficient setup:folders
您必须设置对/cache文件夹的写入权限。
然后您可以在根目录中创建一个index.php或在哪里使用Deficient
<?php #index.php require_once __DIR__ . '/vendor/autoload.php'; use Zofe\Deficient\Deficient; //booting from current directory (needed to find config and other folders) Deficient::boot("./"); //db stuff $results = select('select * from mytable'); //validation $validator = validator(array('title'=>'abc','description'=>'description bla b...'), array('title'=>'required|min:4','description'=>'required')); if ($validator->fails()){ dd( $validator->messages() ); } //translation (return 'thankyou' value @ current locale: /lang/en/messages.php ) echo trans('messages.thankyou'); //eloquent $users = User::all(); //blade echo blade('hello', compact('results','users'));
Laravel Facades
您还可以使用laravel Facades,声明或使用完整的命名空间,例如
<?php use Zofe\Deficient\Deficient; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\DB; ... $validator = Validator::make(.... $results = DB::select(....
需要路由器吗?
Deficient没有laravel路由,但它有一个简单的替代方案:burp路由器。
所以您可以这样做
.. Deficient::boot("./"); route_get('^/user/(\d+)$', function( $id ) { $user = User::find($id); echo blade('user_detail', compact('user')); }); route_post('^/user/(\d+)$', function( $id ) { $user = User::find($id)->update($_POST); echo blade('user_detail', compact('user')); }); route_missing(function() { echo blade('error', array(), 404); die; }); route_dispatch();
要创建基本的index.php、.htaccess和一些路由,您可以使用此命令
(重要:确保您当前应用程序中没有index.php和.htaccess)
php vendor/zofe/deficient/deficient setup:router