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: 7 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-23T14:11:11.000Z (over 3 years ago)
- Last Synced: 2025-02-28T08:43:52.729Z (about 1 year 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.
[](https://packagist.org/packages/initphp/parameterbag) [](https://packagist.org/packages/initphp/parameterbag) [](https://packagist.org/packages/initphp/parameterbag) [](https://packagist.org/packages/initphp/parameterbag) [](https://packagist.org/packages/initphp/parameterbag)

## 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)