PHP Classes

PHP Configurable Interface: Set and get configuration values from one object

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 119 All time: 9,524 This week: 39Up
Version License PHP version Categories
configurable 0.9.0GNU General Publi...8PHP 5, Data types, Configuration, Des...
Description 

Author

This package can set and get configuration values from one object.

It provides an interface and an abstract class that can set and get several configuration values in the same object.

The package allows to set immutable values that can only be set once and cannot be changed after the initial value assignment.

It also allows to switch a set of boolean values all at once.

Innovation Award
PHP Programming Innovation award nominee
March 2022
Number 2
Every application needs to manage configuration values used in different application parts.

Experienced developers usually work on the application in a development environment with specific configuration values adequate for that environment.

In the production environment, applications may use different configuration values in the same application code more suited to the production environment.

This package provides a practical configuration class that allows setting configuration values only once.

This feature is helpful in situations where configuration values will have fixed values that applications should not change.

Such situations are precisely the case when there are application-wide configuration values set only once during application initialization.

The possibility of setting multiple boolean configuration values is also helpful to reduce the necessary code to set different configuration settings assigned to the same boolean value.

Manuel Lemos
Picture of Carlos Artur Curvelo da Matos
  Performance   Level  
Name: Carlos Artur Curvelo da ... <contact>
Classes: 21 packages by
Country: Portugal Portugal
Innovation award
Innovation award
Nominee: 14x

Winner: 2x

Documentation

Configurable Interface

A lot of scripts and packages in modern PHP demand one or more configuration classes. Mostly, those are a set of properties that can be set, changed or retrieved. However, some of the configurations have a peculiar behaviour - such as boolean properties. Also, we want some of the settings to be manageable in the future - for some other we want values to remain immutable after a first setup.

There are plenty of proposed interfaces for that - what is different in this Configurable interface are two methods in particular: immutable() and switch().

This packages brings a Configurable interface and an abstract that comprises a very objective implementation of that. Shortly, we are also going to provide a trait with the same function.

Equipped with standard methods for this kind of class, such as get(), set() and getDefaults (this last retrieving all properties as they are in that moment), both the interface and the abstract propose two new methods:

The immutable() method

The immutable method allows a property to be set or redefined (if the class already brings any default value) just once. After that, the property key is stored in a private variable and any new attempt of setting new values will be ignored.

The switch() method

This method provides a quick and simpler way of changing one or more boolean properties. As the name suggests, any property set as FALSE will be switched to TRUE, so as it makes all TRUE values to become FALSE.


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (3 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
  Plain text file AbstractConfigurable.php Class Class source
  Plain text file Configurable.php Class Class source
  Plain text file ConfigurableException.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:119
This week:0
All time:9,524
This week:39Up
User Comments (1)
Thats a very good class ;-)
2 years ago (José Filipe Lopes Santos)
70%StarStarStarStar