PHPackages                             graste/params - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. graste/params

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

graste/params
=============

Array wrapper that eases the retrieval of values. Has parameters, options and settings and traits for inclusion in other libraries.

v3.1.0(7y ago)107.0k[1 issues](https://github.com/graste/params/issues)MITPHPPHP ^7.0

Since Jun 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/graste/params)[ Packagist](https://packagist.org/packages/graste/params)[ Docs](https://github.com/graste/params)[ RSS](/packages/graste-params/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (4)Dependencies (3)Versions (14)Used By (0)

Params
======

[](#params)

[![Latest-Stable-Version](https://camo.githubusercontent.com/1fd6138bf5610301187f8ae620860bd808f39add8b303a6f90cf2648e2265917/68747470733a2f2f706f7365722e707567782e6f72672f6772617374652f706172616d732f762f737461626c652e737667)](https://packagist.org/packages/graste/params "graste/params on packagist")[![License](https://camo.githubusercontent.com/39ab214eb570e6f4aa58c49058357e8e46547523d07917ebdf22eae40b4a56cc/68747470733a2f2f706f7365722e707567782e6f72672f6772617374652f706172616d732f6c6963656e73652e737667)](LICENSE.md "license file with link to original full text of the license")[![Latest Unstable Version](https://camo.githubusercontent.com/03ae6ed7b4f2aea651c5e8e4370e9b8aab6e592a2fb38d00ceceb93845a8a9f4/68747470733a2f2f706f7365722e707567782e6f72672f6772617374652f706172616d732f762f756e737461626c652e737667)](https://packagist.org/packages/graste/params "graste/params on packagist")[![Build Status](https://camo.githubusercontent.com/878e50f188d45d87282055ecc071ac69fa07220131ce8724e8861b55b28f4986/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6772617374652f706172616d732e706e67)](http://travis-ci.org/graste/params "graste/params on travis-ci")[![Stories in Ready](https://camo.githubusercontent.com/5c3ba5fd732cc54e4068a7a787d2068089c31fa284c426f660ac2814f6b091fa/68747470733a2f2f62616467652e776166666c652e696f2f6772617374652f706172616d732e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/graste/params "graste/params on waffle")[![Total Composer Downloads](https://camo.githubusercontent.com/1114b6cd390a7877df46e8e644e702869235d68ce84703d1edd1a766fa5489ef/68747470733a2f2f706f7365722e707567782e6f72672f6772617374652f706172616d732f642f746f74616c2e706e67)](https://packagist.org/packages/graste/params "graste/params on packagist")

Purpose
-------

[](#purpose)

Array wrapper object that eases the retrieval of values. It provides a `get` method that can return a default value if the given key is missing. In addition to the usage as a normal array and the various `get`, `set`, `has` etc. methods Parameters defines a `getValues($expression)` method that allows the retrieval of values by providing more or less complex expressions. You can easily retrieve values from nested arrays or get several values from different nesting levels with one call. There are traits for convenient creation of configurable classes.

Requirements and installation
-----------------------------

[](#requirements-and-installation)

- PHP ^7.0

Install the library via [Composer](https://getcomposer.org/ "Composer homepage with further documentation"):

`./composer.phar require graste/params [optional version]`

Adding it manually as a vendor library requirement to the `composer.json` file of your project works as well:

```
{
    "require": {
        "graste/params": "^3.0.0"
    }
}
```

Alternatively, you can download a release archive from the [releases](https://github.com/graste/params/releases "graste/params releases on github").

Documentation and usage
-----------------------

[](#documentation-and-usage)

```
$data = array(
    'str' => 'some string',
    'first_level' => 'first level',
    'nested' => array(
        'str' => 'some nested string',
        '2nd level' => 'second level',
    ),
    'more' => array(
        'str' => 'other nested string',
    )
);

// base object of the aliased versions:
$arrayobj = new \Params\ConfigurableArrayObject($array);

// create mutable parameters instance:
$params = new \Params\Parameters($data);
// or initialize an immutable instance that prevents further modifications after construction
$params = new \Params\Immutable\ImmutableParameters($data);

// do you like options instead of parameters in your classes?
$params = new \Params\Options($data);
$params = new \Params\Immutable\ImmutableOptions($data);

// do you like settings instead of parameters in your classes?
$params = new \Params\Settings($data);
$params = new \Params\Immutable\ImmutableSettings($data);

// use it as a recursive object:

$params->has("foo")                           // returns true now
$params->get("str")                           // gives "some string"
$params->get("nested")                        // gives array stored under "nested" key
$params->get("nested")->get('str')            // gives "some nested string"
$params->get("non-existant", "default value") // gives "default value" as given key is non existant
$params->get("nested")->set("foo", "bar")     // sets key "foo" to value "bar" on the "nested" array
$params->getKeys()                            // returns all first level keys
$params->toArray()                            // returns internal array

// or use the mutable methods
$params->set("foo", "bar")                    // sets key "foo" to value "bar"
$params->add(array|ArrayAccess)               // add array or other ArrayAccess implementing object to current instance
$params->clear()                              // empty internal array
$params->map(function($key, $value) { … })    // modifies each value to the value returned by the callback

// retrieve values using expressions

$params->getValues("foo")                               // gives "bar"
$params->getValues("nested.str")                        // gives "some nested string"
$params->getValues('*.str')                             // gives array("some nested string", "other nested string")
$params->getValues('[str, nested.str]')                 // gives array("some string", "some nested string")
$params->getValues('nested."2nd level" || first_level') // gives "second level" as that key exists; other expression not evaluated
$params->getValues('first_level || nested."2nd level"') // gives "first level" as that key exists; other expression not evaluated

// use it as an array:

$params["str"]    // gives "some string"
$params["nested"] // gives the array under the "nested" key
$params[1]        // gives "first level"

// use it as an object with properties

$params->foo = 'bar'          // sets key 'foo' to value 'bar'
$params->filter->bool = 'yes' // sets $params['filter']['bool'] to value 'yes'
```

The expression syntax used is provided by Michael Dowling's [JMESPath](https://github.com/mtdowling/jmespath.php "JMESPath on github").

### Traits

[](#traits)

There are [Traits](http://php.net/manual/en/language.oop5.traits.php "Traits on php.net") may be used for own configurable classes:

- `ImmutableParametersTrait` wraps `parameters`
- `ParametersTrait` wraps `parameters`
- `ImmutableOptionsTrait` wraps `options`
- `OptionsTrait` wraps `options`
- `ImmutableSettingsTrait` wraps `settings`
- `SettingsTrait` wraps `settings`

For fluent API support the methods `add`, `set`, `remove` and `clear` return the class instance they're mixed into.

### ElasticSearch queries

[](#elasticsearch-queries)

The syntax sugar `Parameters` provides is not only nice to define configurable classes, but also eases the creation and modification of ElasticSearch queries:

```
$params->filter->bool->must[1]->term->live = false;
$params->get('filter')->set('bool', …);
$params->filter->bool->must[] = array(…);
```

Contribution
------------

[](#contribution)

Please contribute by [forking](http://help.github.com/forking/ "Github docs on forking a project") and sending a [pull request](http://help.github.com/pull-requests/ "Github docs on pull requests"). More information can be found in the [`CONTRIBUTING.md`](CONTRIBUTING.md) file.

To develop on this repository clone your fork and use the `Makefile` targets:

- `make install` installs composer and all necessary vendor libraries
- `make tests` runs the phpunit tests
- `make code-sniffer-cli` runs the code sniffer on console

The code tries to adhere to the following PHP-FIG standards: [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4 Autoloading Standard"), [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1 Basic Coding Standard") and [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2 Coding Style Guide"). The current license is [MIT](LICENSE.md).

The authors and contributors are mentioned in the [github contributors graph](graphs/contributors) of this repository. The license file must be left intact for attribution and sharing of this work.

Changelog
---------

[](#changelog)

See [`CHANGELOG.md`](CHANGELOG.md) for more information about changes.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 93.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~134 days

Recently: every ~378 days

Total

13

Last Release

2727d ago

Major Versions

v0.2.0 → v1.0.02014-07-01

v1.2.0 → 2.x-dev2014-07-02

2.1.1 → v3.0.02015-03-08

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v3.1.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/88ca3c7aa7051202485dde1d44c952960d66247d25cd94a4ca08f19a0858e605?d=identicon)[graste](/maintainers/graste)

---

Top Contributors

[![graste](https://avatars.githubusercontent.com/u/203540?v=4)](https://github.com/graste "graste (59 commits)")[![shrink0r](https://avatars.githubusercontent.com/u/202678?v=4)](https://github.com/shrink0r "shrink0r (4 commits)")

---

Tags

searchSettingsarrayoptionslibraryparameters

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graste-params/health.svg)

```
[![Health](https://phpackages.com/badges/graste-params/health.svg)](https://phpackages.com/packages/graste-params)
```

###  Alternatives

[graze/data-structure

Data collections and containers

12287.4k8](/packages/graze-data-structure)[dotty/dotty

Easy access to array data using dot notation

1293.8k1](/packages/dotty-dotty)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
