PHP Classes

How Can You Use a PHP Options Array to Configure Options Using Options Resolver: Configure objects with option arrays

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 All time: 10,454 This week: 69Up
Version License PHP version Categories
optionsresolver 1.0The PHP License7Data types, Language, Configuration, P...
Description 

Author

This package can help to configure objects with option arrays.

It provides a resolver class that can take the names of a set of options and default values that will be assumed when an option value is missing.

The resolver class can also process an array to extract option values or use default values for missing options.

The OptionsResolver component helps you configure objects with option arrays.

Innovation Award
PHP Programming Innovation award nominee
December 2022
Number 8
Many classes need to be configured using options provided by the developers in the code that calls the classes' functions.

One way to pass options values is to use arrays with the names and the values of the options that will be changed.

This package simplifies the processing of options arrays that are passed to classes by extracting the values from arrays or default values defined within the class.

Manuel Lemos
Picture of Boss Ibrahim Mussa
  Performance   Level  
Name: Boss Ibrahim Mussa <contact>
Classes: 13 packages by
Country: Congo Congo
Age: ???
All time rank: 28911 in Congo Congo
Week rank: 180 Up1 in Congo Congo Equal
Innovation award
Innovation award
Nominee: 5x

Example

<?php
/*
 * Copyright (c) 2022.
 * The OptionsResolver component helps you configure objects with option arrays. It supports default values, option constraints and lazy options.
 */

use Wepesi\Demo\Database;

include
__DIR__."/../vendor/autoload.php";
include
__DIR__."/Database.php";

$database = new Database([
   
'dbname' => 'app',
]);
// Uncaught InvalidArgumentException: The required option "username" is missing.

// $database = new Database([
// 'host' => 'localhost',
// 'dbname' => 'app',
// 'username' => 'root',
// 'password' => 'root',
// ]);
var_dump($database->options);


Details

OptionsResolver

Build Status Source Version Downloads License Issues

description

The OptionsResolver component helps you configure objects with option arrays. It supports default values, option constraints and lazy options.


  Files folder image Files (8)  
File Role Description
Files folder image.github (1 directory)
Files folder imagedemo (2 files)
Files folder imagesrc (2 files, 1 directory)
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 (8)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (8)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files (8)  /  demo  
File Role Description
  Plain text file Database.php Class Class source
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (8)  /  src  
File Role Description
Files folder imageTraits (1 file)
  Plain text file Option.php Class Class source
  Plain text file OptionsResolver.php Class Class source

  Files folder image Files (8)  /  src  /  Traits  
File Role Description
  Plain text file ExceptionTraits.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:62
This week:0
All time:10,454
This week:69Up