Download the PHP package solidworx/toggler without Composer

On this page you can find all versions of the php package solidworx/toggler. 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 toggler

Toggler

Test Suite codecov

Toggler is a feature toggle library for PHP. It allows you to enable or disable features based on a toggle switch. This is useful in a continues deployment environment, where you can deploy not-yet-ready features which are disabled, and just enable them when the feature is complete.

Table of Contents

Requirements

Toggler requires PHP 7.3+ and Symfony 4.0+

Installation

Composer

Usage

Quick Example

You can then check if a feature is active or not using the isActive call

StorageFactory

Toggler comes with many storage adapters to store the configuration. The most basic is the ArrayStorage class, which takes an array of features.

The StorageFactory class acts as a factory to create the config. You can pass it any value, and it will determine which storage adapter to use. To get an instance of the config, you can use the static factory method

Each feature flag need to be a truthy value in order to be enabled.

The following truthy values are accepted:

Using callbacks

You can also use closures or callbacks to retrieve the value

Storage Adapters

Toggler supports various storage adapters to store the config.

Array

The most basic config is using an array with the ArrayStorage adapter.

ENV

Reads values from environment variables.

YAML

In order to use yml files for config, you need to include the Symfony Yaml Component

To install and use the Yaml component, run the following command from the root of your project:

Then you can define your config using a yaml file

Pass the path to the yml file to your config

PHP File

You can store your config in a separate PHP file. This fille needs to return an array with the config. By default, PHP files always use the ArrayStorage adapter.

Pass the path to the PHP file to your config

Redis

You can use Redis to store the configs.

You will then need to either install the Predis library or the Redis PHP extension.

To install Predis, run the following command from the root of your project:

The RedisStorage adapter can take any class instance of Redis, RedisArray, RedisCluster or Predis\Client.

Database

You can use a database to store the configs.

Toggler comes with a PDOStorage adapter, which can be used with any database that supports PDO.

Persistent Storage

Toggler supports persisting config values if a storage adapter implements the SolidWorx\Toggler\Storage\PersistenStorageInterface.

The following storage adapters currently supports persisting config values:

To update a feature, use the set method:

Toggle a feature based on context

To enable a feature only under specific conditions (E.G only enable it for users in a certain group, or only enable it for 10% of visitor etc)

Each feature in the config can take a callback, where you can return a truthy value based on any logic you want to add:

Callbacks that takes any arguments, should be called with the context:

Using Symfony Expression Language

You can use the Symfony Expression Language Component to create expressions for your features.

To install and use the Expression Language component, run the following command from the root of your project:

Then you can create an expression for your feature:

When checking the feature, you need to pass the context to use in your expression:

Twig Integration

Toggler comes with an optional Twig extension, which allows you to toggle elements from Twig templates.

To use the extension, register it with Twig

or if you use symfony, register it as a service.

Note: When using the [Symfony Bundle](Symfony Integration), the twig extension is automatically registered.

Then you can use the toggle tag in twig templates:

To add an alternative if a feature is not available, use the else tag

To use context values with the tag, you can pass it using the with keyword:

You can also use the toggle() function for conditions

Symfony Integration

Toggler comes with integration with the Symfony framework.

To enable toggler inside symfony, register the bundle

Then create a config/packages/toggler.yaml config file, to enable features

If you want to use an expression for a feature config, you can use the @= syntax:

If you want to use a storage class, you can use the storage config parameter to define a service for the storage:

Note: The features and storage options can't be used together. You must use either the one or the other. At least one of the two must be defined.

Note: When using the Symfony bundle, the twig extension is automatically registered.

Note: The symfony/security-core package is required with symfony/framework-bundle.

Console Commands

The Symfony Bundle comes with 2 pre-registered console commands.

Get the status of a feature

To see if a feature is enabled or not, run the following command

This will output the status of a feature.

You can also get the status of multiple features by passing in multiple values:

This will show whether the features foo, bar and baz is enabled or not.

Get the value using context values

To test if a feature will be enabled under certain conditions, you can pass context values to the command using either the -c or --context flags. Multiple values for the context can be provided.

Note: Context values can only be strings. Objects are not supported.

Set the value of a feature

You can enable or disable a feature using the toggler:set command.

Note: You can only change the status of a feature if you are using a persistent storage.

This will enable the foo feature.

List all available features

You can list all available features using the toggler:list command.

This will display all available features and their status.

Testing

To run the unit tests, execute the following command

Contributing

See CONTRIBUTING

License

Toggler is open-sourced software licensed under the MIT license

Please see the LICENSE file for the full license.


All versions of toggler with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
symfony/polyfill-php80 Version ^1.20
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 solidworx/toggler contains the following files

Loading the files please wait ....