daylerees / scientist-laravel
允许 Scientist 库与 Laravel PHP 框架一起使用。
0.1.1-alpha
2016-02-05 23:31 UTC
Requires
- daylerees/scientist: ^0.1.1@alpha
- laravel/framework: 5.*
This package is not auto-updated.
Last update: 2024-09-14 17:48:28 UTC
README
Laravel 的 Scientist
允许使用 Scientist 库 与 Laravel PHP 框架 一起使用。
安装
使用 Composer 需要安装最新版本的 Scientist Laravel。
composer require daylerees/scientist-laravel
接下来,将服务提供者添加到你的 Laravel 项目的 config/app.php
文件的 providers
部分。
<?php return [ /* |-------------------------------------------------------------------------- | Autoloaded Service Providers |-------------------------------------------------------------------------- | | The service providers listed here will be automatically loaded on the | request to your application. Feel free to add your own services to | this array to grant expanded functionality to your applications. | */ 'providers' => [ /* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Scientist\Laravel\ScientistServiceProvider::class, ], ];
最后,在 config/app.php
的 aliases
部分注册 Facade。
<?php return [ /* |-------------------------------------------------------------------------- | Class Aliases |-------------------------------------------------------------------------- | | This array of class aliases will be registered when this application | is started. However, feel free to register as many as you wish as | the aliases are "lazy" loaded so they don't hinder performance. | */ 'aliases' => [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Scientist' => Scientist\Laravel\Facade::class, ], ];
现在你可以开始使用了!
用法
你可以通过 Scientist
Facade 访问 Scientist 实验室。
<?php $value = Scientist::experiment('foo') ->control($controlCallback) ->trial('First trial.', $trialCallback) ->run();
或者,将实验室注入到解析的类或控制器动作中。
<?php use Scientist\Laboratory; class FooController extends Controller { public function index(Laboratory $laboratory) { return $laboratory->experiment('foo') ->control(function() { ... }) ->trial('First trial.', function() { ... }) ->run(); } }
请参阅 Scientist 文档以获取更多信息!
享受吧!