定制 simongenin/laravelvariables 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simongenin/laravelvariables

Composer 安装命令:

composer require simongenin/laravelvariables

包简介

Refactor variables that are meant to be global out of your source code

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固