initphp/parameterbag

InitPHP Parameter Bag Library

1.1.2 2022-11-23 12:55 UTC

This package is auto-updated.

Last update: 2024-10-23 19:08:37 UTC


README

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