Skip to content

A simple library to store data with key=value relationship and access it easily when you need it.

License

Notifications You must be signed in to change notification settings

InitPHP/ParameterBag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InitPHP ParameterBag

Single and multi-dimensional parameter bag.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

parameterbag

Installation

composer require initphp/parameterbag

Requirements

  • PHP 7.2 or later

Usage

require_once "vendor/autoload.php";
use \InitPHP\ParameterBag\ParameterBag;

$parameter = new ParameterBag($_GET);

// GET /?user=muhametsafak
echo $parameter->get('user', null); // "muhametsafak"

Using nested arrays

require_once "vendor/autoload.php";
use \InitPHP\ParameterBag\ParameterBag;

$data = [
    'database'  => [
        'dsn'           => 'mysql:host=localhost',
        'username'      => 'root',
        'password'      => '123456'
    ]
];

$parameter = new ParameterBag($data, ['isMulti' => true, 'separator' => '.']);

$parameter->get('database.username'); // "root" 
$parameter->has('database.charset'); // false

Methods

has()

public function has(string $key): bool;

get()

public function get(string $key, mixed $default = null): mixed;

set()

public function set(string $key, mixed $value): \InitPHP\ParameterBag\ParameterBagInterface;

remove()

public function remove(string ...$keys): \InitPHP\ParameterBag\ParameterBagInterface;

all()

public function all(): array;

merge()

public function merge(array|\InitPHP\ParameterBag\ParameterBagInterface ...$merge): \InitPHP\ParameterBag\ParameterBagInterface;

Credits

License

Copyright © 2022 - MIT License

About

A simple library to store data with key=value relationship and access it easily when you need it.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages