PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 118 All time: 9,517 This week: 52Up
Version License PHP version Categories
configurable 0.9.0GNU General Publi...8PHP 5, Data types, Configuration, Des...


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 ... is available for providing paid consulting. Contact Carlos Artur Curvelo da ... .
Classes: 19 packages by
Country: Portugal Portugal
Age: 46
All time rank: 288639 in Portugal Portugal
Week rank: 289 Up5 in Portugal Portugal Up
Innovation award
Innovation award
Nominee: 13x

Winner: 2x


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  
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 Doc. Documentation

  Files folder image Files  /  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

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,517
This week:52Up
User Comments (1)
Thats a very good class ;-)
2 years ago (Josť Filipe Lopes Santos)