Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/initphp/parameterbag
A simple library to store data with key=value relationship and access it easily when you need it.
https://github.com/initphp/parameterbag
parameter-bag php
Last synced: 2 months ago
JSON representation
A simple library to store data with key=value relationship and access it easily when you need it.
- Host: GitHub
- URL: https://github.com/initphp/parameterbag
- Owner: InitPHP
- License: mit
- Created: 2022-03-14T14:52:16.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-23T14:11:11.000Z (about 2 years ago)
- Last Synced: 2024-11-18T09:43:03.135Z (2 months ago)
- Topics: parameter-bag, php
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InitPHP ParameterBag
Single and multi-dimensional parameter bag.
[![Latest Stable Version](http://poser.pugx.org/initphp/parameterbag/v)](https://packagist.org/packages/initphp/parameterbag) [![Total Downloads](http://poser.pugx.org/initphp/parameterbag/downloads)](https://packagist.org/packages/initphp/parameterbag) [![Latest Unstable Version](http://poser.pugx.org/initphp/parameterbag/v/unstable)](https://packagist.org/packages/initphp/parameterbag) [![License](http://poser.pugx.org/initphp/parameterbag/license)](https://packagist.org/packages/initphp/parameterbag) [![PHP Version Require](http://poser.pugx.org/initphp/parameterbag/require/php)](https://packagist.org/packages/initphp/parameterbag)
![parameterbag](https://initphp.github.io/logos/parameterbag.png)
## Installation
```
composer require initphp/parameterbag
```## Requirements
- PHP 7.2 or later
## Usage
```php
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
```php
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()`
```php
public function has(string $key): bool;
```#### `get()`
```php
public function get(string $key, mixed $default = null): mixed;
```#### `set()`
```php
public function set(string $key, mixed $value): \InitPHP\ParameterBag\ParameterBagInterface;
```#### `remove()`
```php
public function remove(string ...$keys): \InitPHP\ParameterBag\ParameterBagInterface;
```#### `all()`
```php
public function all(): array;
```#### `merge()`
```php
public function merge(array|\InitPHP\ParameterBag\ParameterBagInterface ...$merge): \InitPHP\ParameterBag\ParameterBagInterface;
```## Credits
- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) <>
## License
Copyright © 2022 - [MIT License](./LICENSE)