Download the PHP package ericdowell/feature-toggle without Composer

On this page you can find all versions of the php package ericdowell/feature-toggle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package feature-toggle

Feature Toggles

CircleCI StyleCI Test Coverage Maintainability

License Latest Stable Version Latest Unstable Version Total Downloads

A simple feature toggle api for Laravel applications.

Table of Contents

Installation

Install using composer by running:

Publish the feature-toggle.php config file by running:

Testing

Run composer test.

Usage

If a feature toggle is not defined then isActive will return false.

Toggle Booting

The Feature Toggle Api will pull all possible toggles at the boot of the application. This design allows there to be one database/cache/redis query instead of possibly many calls. This only becomes a problem if there're 100s of feature toggles.

Be mindful of how many database toggles are setup at given time, instead setup or move toggles to the local provider in config/feature-toggle.php.

Helper Functions

feature_toggle_api:

Or a shorter function that does the same as above called feature_toggle:

The feature_toggle function also allows a second parameter to be passed to allow for checking if the toggle is active (true) or if it is inactive (false):

The second parameter will parse as the local toggle does, read more in the Toggle Parsing section to learn more.

Use with Laravel Blade Custom Directive

This custom directive uses the feature_toggle helper function directly, you can expect the same behavior:

Or if you'd like to check if the Example is inactive then you may pass a falsy value as the second parameter:

Or you can use the normal @if blade directive and call feature_toggle function directly:

Use with Laravel Middleware

The middleware signature is as follows:

Where status and abort are optional parameters. status will default to true (truthy) and abort will default to 404 status code. name is required.

Examples:

Use with Laravel Task Scheduling

You can use the built-in when function in combination with the feature_toggle helper function in the app/Console/Kernel.php schedule method.

Use with Laravel Validation

There are three ways you can use the validation logic:

Simple String

Use the normal simple string signature via required_if_feature:

Where status is an optional parameter. status will default to true (truthy). name parameter is required.

Via Illuminate\Validation\Rule

A macro method has been added to the Rule class called requiredIfFeature:

requiredIfRule Method on FeatureToggleApi

You may also use the requiredIfRule method on the FeatureToggleApi/feature_toggle_api Facade or helper function:

Toggle Providers

The default feature toggle providers are as follows:

You can pass the feature_toggle_api helper function one of the above strings to get the toggle provider:

Or you can access each toggle provider via:

E.g.

If you would like to set the providers in code you may call the following in the boot method of your AppServiceProvider:

Add Additional Toggle Providers

You may add additional custom toggle providers or override the default toggle providers by adding them to the drivers key within config/feature-toggle.php:

Then just add them in the order you'd like them to be checked within providers as you would the defaults:

Local Feature Toggles

To add new toggle(s) you will need to update the published config/feature-toggles.php file:

Toggle Parsing

The value passed from the .env file or set directly within config file can be:

Conditional Feature Toggles

To add new conditional toggle(s) you will need to call feature_toggle_api()->setConditional method:

NOTE: The function passed to setConditional does not get called right away by default, it is deferred to allow the Laravel app to bootstrap User/Session information. The conditional function is only called once and the value is cached to help prevent expensive operations from being recalculated when adding additional conditional toggles. Because of this design it is best to define these in AppServiceProvider@boot or in a FeatureToggleServiceProvider@boot that you create.

Eloquent Feature Toggles

To use the eloquent driver you will need to update the feature-toggle config or setProviders method call, place the following within the providers key:

OR

NOTE: Be sure to place this value in the order you would like it to be prioritized by the feature toggle api.

Database Migration

By default the migration for feature_toggles is not loaded, to load this you can update the options key within feature-toggle config setting the useMigrations value to true:

If you would like to set the useMigrations in code you may call the following in the register method of your AppServiceProvider:

You may also publish the migrations to your application by running the following:

Once you've used one of the methods above, you can run the following command to update your database with the feature_toggles migration(s):

Eloquent Model

If you would like to use a different eloquent model you may do so by adding model to the config file:

QueryString Toggle Provider

To use the querystring driver you will need to update the feature-toggle config or setProviders method call, place the following within the providers key:

When making a request to your application you may now use the following query strings to make feature toggles active/inactive:

e.g. http://localhost/?feature=Example&feature_off[]=Example%20Off&feature_off[]=Example%20Query%20String

The following example will result in Example as active and Example Off/Example Query String as inactive. NOTE: This will only be true if the querystring provider is placed above other toggle providers that haven't already defined these feature toggles.

Configure Query String Keys

If you'd like to configure what the active/inactive feature toggle input keys are you may add activeKey and inactiveKey to config file.

Below is an example of configuring the query string keys as active and inactive:

Add Api Key Authorization

To keep users or bad actors from enabling/disabling feature toggles via the querystring toggle provider you may configure the driver with a token/api key. By default the query string input is configured as feature_token, but this can be also be configured to any value.

Redis Toggle Provider

To use the redis driver you will need to update the feature-toggle config or setProviders method call, place the following within the providers key:

There are three options that can be configured:

Current implementation requires the array of toggles to be serialized in redis, you can use Illuminate\Cache\RedisStore forever method to persist toggle values.

Session Toggle Provider

To use the session driver you will need to update the feature-toggle config or setProviders method call, place the following within the providers key:

Frontend Feature Toggle Api

Place the following in your main layout blade template in the <head> tag.

Then create a new js file within resources/js called featureToggle.js:

Expose on the window within app.js:

and/or simply use featureToggle within your other js files:

and/or create a Feature component that uses featureToggle.js:

Road Map

v1.x


All versions of feature-toggle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2.5|^8.0
ext-json Version *
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ericdowell/feature-toggle contains the following files

Loading the files please wait ....