simongenin/laravelvariables
Composer 安装命令:
composer require simongenin/laravelvariables
包简介
Refactor variables that are meant to be global out of your source code
README 文档
README
Refactor variables that are meant to be global out of your source code.
Note
This is my first package.
Installation
Via Composer
$ composer require simongenin/laravelvariables
Publish the config file were your global variables will live
$ php artisan vendor:publish --tag=variables.config
Usage
It does the same thing as the config helper, with more ways to call it.
The goal here was to have a strict separation for variables that are global, but don't belong in another configuration file.
Once installed, you will have a new configuration file, called "variables.php". Just like any other config file, you can define many values by using nested arrays.
Here's an exemple of what it could be used for:
<?php return [ /** * Define variables that have a reason to be global */ 'subscription' => [ 'monthly' => 19, 'yearly' => 199, 'lifetime' => 299 ], 'subtitle' => [ 'ATest' => 'A nice little package!', 'BTest' => 'A wonderful little package!', ], 'me' => [ 'email' => env('PERSONAL_CONTACT_MAIL', 'no@hotmail.com') ] ];
And here is how you can retrieve the values in your code:
/* * There are several way you can ask for a variable */ $caller = new SimonGenin\LaravelVariables\LaravelVariables(); $cost = $caller->get('subscription.yearly'); $cost = $caller->__v('subscription.yearly'); $cost = $caller('subscription.yearly'); /* * You can use the config helper */ $cost = config('variables.subscription.lifetime'); /* * You can use the app helper to get the singleton instance */ $caller = app('variables'); $cost = $caller('subscription.monthly'); $cost = app('variables')->get('subscription.monthly'); $cost = app('variables')('subscription.monthly'); /* * You can call it dynamically by the resource name in camel case */ $caller = new SimonGenin\LaravelVariables\LaravelVariables(); $cost = $caller->subscriptionYearly(); /* * Same, but partly method call name and partly arguments */ $caller = new SimonGenin\LaravelVariables\LaravelVariables(); $cost = $caller->subscription('yearly'); /** * The two last methods are fancy, but a hell regarding project management. * Don't abuse it, especially on big projects. */
License
MIT
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-28