Giter Club home page Giter Club logo

php-typed-config's Introduction

Strong Typed Config

A lightweight and strong typed configuration file loader that supports PHP, INI, XML, JSON, and YAML files.

This package is a wrapper around hassankhan/config.

Social Legal Release Tests Code
Gitter License Latest Stable Version
Build Status
Code Coverage
Scrutinizer Code Quality

Manual

Instantiating Strong Typed Config

Creating an instance of Strong Typed Config requires passing an instance of Noodlehaus\Config:

use Noodlehaus\Config;
use SetBased\Config\TypedConfig;

$config = new TypedConfig(new Config('config.json'));

Getting the value of a key

There are two flavors of methods for getting a configuration value:

  • Mandatory keys (man for short). These methods will never return a null value.
  • Optional keys (opt for short). These methods will return null if the key does not exists or has value null.

All methods will try to cast the value of a key to the required type using package setbased/helper-cast. I.e. if the value of key is string(1) method getManBool will return bool(true) and method getManInt will return int(1).

All methods have two arguments:

  1. The key.
  2. An optional default value. this value will be returned if the key does not exists or has value null.

The table below gives an overview of all methods for getting the value of a key.

Method Null Value Return Type
getManArray throws an exception array
getManBool throws an exception bool
getManFiniteFloat throws an exception float
getManFloat throws an exception float
getManInt throws an exception int
getManString throws an exception string
getOptArray returns null array|null
getOptBool returns null bool|null
getOptFiniteFloat returns null float|null
getOptFloat returns null float|null
getOptInt returns null int|null
getOptString returns null string|null

Installation

Strong Typed Config can be installed using composer:

composer require setbased/typed-config

License

This project is licensed under the terms of the MIT license.

php-typed-config's People

Contributors

prwater avatar

Watchers

 avatar  avatar

Forkers

haizadvnet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.