LOAD is a PHP library for configuration loading to APCu

Related tags

Configuration load
Overview

LOAD Build Status

LOAD is a PHP library for configuration loading to APCu

Sources

Available sources for configuration loading are:

  • PHP file
  • Consul
  • Environment variables

Install

You can install load using Composer by running the following:

composer require beatlabs/load

Usage

PHP file:

You can read a PHP file that returns an array.

For example with config.php:

return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]   
];

You can use the following:

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

Consul (Default server localhost:8500):

$loader = new BeatLabs\Load\Loader\ConsulLoader();
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

Consul (Custom server myhost:8000 with root path "services/my-service"):

"myhost:8000" ]; $loader = new BeatLabs\Load\Loader\ConsulLoader('services/my-service', $options); $config = new BeatLabs\Load\Config([$loader]); $config->load(); // Get configuration values $val = $config->get('var'); ">
// You can get all available options here: https://docs.guzzlephp.org/en/6.5/quickstart.html#creating-a-client
$options = [
    "base_uri" => "myhost:8000"
];
$loader = new BeatLabs\Load\Loader\ConsulLoader('services/my-service', $options);

$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

Environment variables:

You can have a prefix for environment variables so that you only include environment variables that start with that prefix. That gives the ability to load only what needed instead of entire environment as a configuration.

// Set variable
$loader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_'); // Define environment variables prefix to be loaded
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');

Multiple loaders:

$consulLoader = new BeatLabs\Load\Loader\ConsulLoader();
$fileLoader = new BeatLabs\Load\Loader\PHPLoader('config.php');
$envLoader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_');
$config = new BeatLabs\Load\Config([$consulLoader, $fileLoader, $envLoader]);
$config->load();

// Get configuration values
$val = $config->get('var');

Loaders are executed in the order they are defined. Each loader will override any configuration loaded from previous loaders.

Custom cache

By default, load uses APCu to cache configuration, but you can use your own cache (ex. Redis, Memcache etc.) by implementing the BeatLabs\Load\Interfaces\Cache interface and set it to Config constructor.

For example:

$cache = new CustomCache();
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], $cache);
$config->load();

Configuration flattening

Configuration values that have nested sub-values are flattened and can be fetched without further process.

For example:

config.php

return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]   
];

Will behave like this:

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var.sub-var'); // $val = 'sub-val'

The default separator is ., but you can set your own at Config constructor.

For example:

$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], null, '_');
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var_sub-var'); // $val = 'sub-val'

Reload configuration

Configuration can be reloaded by sending SIGUSR2 to PHP running process for CLI scripts and in php-fpm master process for HTTP scripts.

Reloading can also be invoked in code by using the following code:

$config->reload();

How to Contribute

See Contribution Guidelines

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project and its community you agree to abide by those terms.

Changelog

You can see changelog here

You might also like...
All PHP functions, rewritten to throw exceptions instead of returning false

Safe PHP This project is deprecated Because of how this project needs to be in sync with the official PHP documentation, maintaining a set of function

A PHP parser for TOML

TOML parser for PHP A PHP parser for TOML compatible with TOML v0.4.0. Support: Installation Requires PHP = 7.1. Use Composer to install this package

Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

This small PHP package assists in the loading and parsing of VTT files.

VTT Transcriptions This small PHP package assists in the loading and parsing of VTT files. Usage use Laracasts\Transcriptions\Transcription; $transcr

A package for adding loading spinners to your Laravel Artisan commands
A package for adding loading spinners to your Laravel Artisan commands

Table of Contents Overview Installation Requirements Install the Package Usage Adding Loading Spinners to Commands Adding Text to the Spinner Customis

Customized loading ⌛ spinner for Laravel Artisan Console.

Laravel Console Spinner Laravel Console Spinner was created by Rahul Dey. It is just a custom Progress Bar inspired by icanhazstring/symfony-console-s

A base API controller for Laravel that gives sorting, filtering, eager loading and pagination for your resources

Bruno Introduction A Laravel base controller class and a trait that will enable to add filtering, sorting, eager loading and pagination to your resour

Laravel Helpers Automatic Loading System

About Laravel Helpers Automatic Load Laravel Helpers Automatic Loading System Doc: Copy the Helpers folder and paste it on app folder Then Go To app/P

Restart a CLI process without loading the xdebug extension.

composer/xdebug-handler Restart a CLI process without loading the Xdebug extension, unless xdebug.mode=off. Originally written as part of composer/com

A plugin that teleports to world with Fancy Loading screen like WaterdogPE!

FancyTeleportScreen This is was made by Dyzer Development This plugin was allows you to teleport other world with LoadingScreen! Information This is w

🔍 This is a collection of utilities for routing and loading components.
🔍 This is a collection of utilities for routing and loading components.

Router Utilities - PHP Introduction A day will come when I will write documentation for this library. Until then, you can use this library to create r

This library extends the 'League OAuth2 Client' library to provide OpenID Connect Discovery support for supporting providers that expose a .well-known configuration endpoint.

OpenID Connect Discovery support for League - OAuth 2.0 Client This library extends the League OAuth2 Client library to provide OpenID Connect Discove

PPM is a process manager, supercharger and load balancer for modern PHP applications.
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM is a process manager, supercharger and load balancer for modern PHP applications.
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

🤯 High-performance PHP application server, load-balancer and process manager written in Golang
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Load .env files for PHP.

PHP DotEnv Loader Simple library to load and get values from .env file(s). Install composer require murilo-perosa/dot-env How to Use Namespace use Mur

Owner
Beat Labs
Beat Labs
Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and string

Config Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and strings. Requirements Config

Hassan Khan 948 Nov 27, 2022
A better YAML configuration file management virion for PocketMine-MP 4

BetterConfig WARNING: This virion is under development and haven't been tested. Do not use this virion unless you know what you're doing. Contribution

KygekTeam International 1 Apr 30, 2022
zend-config is designed to simplify access to configuration data within applications

zend-config is designed to simplify access to configuration data within applications

Zend Framework 89 Jan 13, 2022
Yaml Configuration support for CakePHP 3

implements most of the YAML 1.2 specification using Symfony Yaml Component to CakePHP 3 for parsing config files

Borhaneddine Guemidi 11 Nov 10, 2020
Map request on your DTO object with zero configuration.

Map request on your DTO object with zero configuration. Install composer require prugala/symfony-request-dto Usage Create a DTO that implements the in

Piotr Rugala 12 Nov 17, 2022
PHP client library for the Square Connect APIs

Square Connect PHP SDK - RETIRED replaced by square/square-php-sdk NOTICE: Square Connect PHP SDK retired The Square Connect PHP SDK is retired (EOL)

Square 115 Sep 28, 2022
This library can parse a TypeSchema specification either from a JSON file, or from PHP classes using reflection and annotations.

This library can parse a TypeSchema specification either from a JSON file, or from PHP classes using reflection and annotations. Based on this schema it can generate source code and transform raw JSON data into DTO objects. Through this you can work with fully typed objects in your API for incoming and outgoing data.

Apioo 54 Jul 14, 2022
An object-oriented option parser library for PHP, which supports type constraints, flag, multiple flag, multiple values, required value checking

GetOptionKit Code Quality Versions & Stats A powerful option parser toolkit for PHP, supporting type constraints, flag, multiple flag, multiple values

Yo-An Lin 140 Sep 28, 2022
The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function that you can use instead of var_dump().

VarDumper Component The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function t

Symfony 7.1k Dec 2, 2022
A beautiful, fully open-source, tunneling service - written in pure PHP

Expose A completely open-source ngrok alternative - written in pure PHP. Documentation For installation instructions, in-depth usage and deployment de

Beyond Code 3.9k Nov 27, 2022