jamalosm / config
Easy to use class for working with php configuration files
This package's canonical repository appears to be gone and the package has been frozen as a result.
1.0.1
2019-05-19 15:47 UTC
Requires
- php: ^7.1.3
- illuminate/config: ^5.5,<5.9
- symfony/finder: ^4.2
This package is auto-updated.
Last update: 2022-11-20 00:14:58 UTC
README
Installing
`composer require jamalosm/config 1.*`
Usage
<?php // config/app.php return [ "name" => 'B-ONE Application', "versions" => [ "v1" => "19.02.2017", "v2" => "23.04.2018", ] ];
<?php // index.php require 'vendor/autoload.php'; $instance = \BONE\Config\Config::getInstance(__DIR__."/config"); $instance->get('app.name'); //B-ONE Application
###Methods
has(string $key) :bool
Determine if the given configuration value exists.
$instance->has('app.name'); //true $instance->has('app.path'); //false
get($key, $default = null)
Get the specified configuration value.
$instance->get('app.name'); //'B-ONE Application' $instance->get('app.versions'); /* [ "v1" => "19.02.2017", "v2" => "23.04.2018" ] */ $instance->get('app.path'); //NULL $instance->get('app.path', 'application'); //'application' $instance->get(['app.name','app.versions.v1']); /* [ "app3.name" => "B-ONE Application", "app3.versions.v1" => "19.02.2017", ] */ $instance->get(['app.name','app.versions.v1','app.path']); /* [ "app3.name" => "B-ONE Application", "app3.versions.v1" => "19.02.2017", "app.path" => null ] */
set($key, $value = null)
Set a given configuration value.
//Example 1 $instance->get('app.path'); //NULL $instance->set('app.path', '\app\path'); $instance->get('app.path'); //'\app\path' //Example 2 $instance->get('app'); /* [ "name" => "B-ONE Application", "versions" => [ "v1" => "19.02.2017", "v2" => "23.04.2018", ], "path" => "\app\path" ] */ $instance->set([ "app.versions.v1" => "19.02.2019", "app.versions.v3" => "19.06.2020", "app.path" => '\app\folder' ]) $instance->get('app'); /* [ "name" => "B-ONE Application", "versions" => [ "v1" => "19.02.2019", "v2" => "23.04.2018", "v3" => "19.06.2020", ], "path" => "\app\folder" ] */ //Example 3 $instance->set([ "app" => [ "name" => "Laravel Application", "versions" => [ "v4" => "12.07.2013", ] ] ]); $instance->get('app'); /* [ "name" => "Laravel Application", "versions" => [ "v4" => "12.07.2013", ] ] */
prepend($key, $value)
Prepend a value onto an array configuration value.
$instance->get('app.versions'); /* [ "v1" => "19.02.2017", "v2" => "23.04.2018", ] */ $instance->prepend('app.versions',"12.07.2013") $instance->get('app.versions'); /* [ 0 => "12.07.2013", "v1" => "19.02.2017", "v2" => "23.04.2018", ] */
push($key, $value)
Push a value onto an array configuration value.
$instance->get('app.versions'); /* [ "v1" => "19.02.2017", "v2" => "23.04.2018", ] */ $instance->prepend('app.versions',"12.07.2013") $instance->get('app.versions'); /* [ "v1" => "19.02.2017", "v2" => "23.04.2018", 0 => "12.07.2013", ] */
all()
Get all of the configuration items for the application.
$instance->all(); /* [ "app" => [ "name" => "B-ONE Application", "versions" => [ "v1" => "19.02.2017", "v2" => "23.04.2018", ], "path" => "\app\path" ] ] */