PHPackages                             mrself/options - 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. mrself/options

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

mrself/options
==============

v2.19.7(5y ago)0238↓85.7%[2 issues](https://github.com/mrself/php-options/issues)[1 PRs](https://github.com/mrself/php-options/pulls)7PHP

Since Jan 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mrself/php-options)[ Packagist](https://packagist.org/packages/mrself/options)[ RSS](/packages/mrself-options/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (8)Versions (62)Used By (7)

Demo
----

[](#demo)

Add the trait to your class

```
class ClassWithOptions
{
    use \Mrself\Options\WithOptionsTrait;
}
```

Add the first option:

```
use Mrself\Options\Annotation\Option;

class ClassWithOptions
{
    use \Mrself\Options\WithOptionsTrait;

    /**
    * The required option to initialize the class
     * @Option()
     * @var array
     */
    private $arrayOption;

    public function getOption()
    {
        return $this->arrayOption;
    }
}
```

Initialize the class:

```
$instance = ClassWithOptions::make(['arrayOption' => ['key' => 'value']]);

// True
$instance->getOption()['key'] === 'value';
```

An exception is thrown if the option is of missed:

```
// Exception \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
$instance = ClassWithOptions::make();
```

More examples
-------------

[](#more-examples)

Type resolving:

```
use Mrself\Options\Annotation\Option;

class ClassWithOptions
{
    use \Mrself\Options\WithOptionsTrait;

    /**
     * @Option()
     * @var array
     */
    private $arrayOption;

    public function getOption()
    {
        return $this->arrayOption;
    }
}

$notArray = 1;
// Exception
ClassWithOptions::make(['arrayOption' => $notArray]);
```

```
use Mrself\Options\Annotation\Option;

class ClassWithOptions
{
    use \Mrself\Options\WithOptionsTrait;

    /**
     * @Option()
     * @var \DateTime
     */
    private $arrayOption;

    public function getOption()
    {
        return $this->arrayOption;
    }
}

$notDate = 1;
// Exception
ClassWithOptions::make(['arrayOption' => $notDate]);
```

Using with container (see mrself/container)
-------------------------------------------

[](#using-with-container-see-mrselfcontainer)

```
use Mrself\Options\Annotation\Option;
use Mrself\Container\Container;
use Mrself\Container\Registry\ContainerRegistry;

$service = new \stdClass();
$service->property = 'myProperty';

$container = Container::make();
$container->set('service', $service);
ContainerRegistry::add('App', $container);

class ClassWithOptions
{
    use \Mrself\Options\WithOptionsTrait;

    /**
     * @Option()
     * @var \stdClass
     */
    private $service;

    public function getService()
    {
        return $this->service;
    }
}

$instance = ClassWithOptions::make();

// True
$instance->getService()->property === 'myProperty';
```

This trait can be used with Symfony or another framework with public services.

Suspend all errors:

```
$object->init(['.silent' => true]);
```

---

If an annotated property has a non-primitive type, the property can be resolved only of that type:

```
$object = new class {
    /**
     * @Option
     * @var \Reflection
     */
    public $option1;
};

// Throws since 'option1' expected a value of type '\Reflection'
$object->init(['option1' => 1]);
```

---

Primitive types are not processed so they should be declared in array schema:

```
new class {
    protected function getOptionsSchema()
    {
        return [
            'allowedTypes' => ['option1' => \Reflection::class]
        ];
    }
 };
```

---

Array schema has a higher priority than an annotation schema

---

An option can be set as optional:

```
$object = new class {
    /**
     * @Option(required=false)
     * @var \Reflection
     */
    public $option1;
};
```

---

Options can be preset by a specific key:

```
$object = new class {

    /**
     * @Option()
     * @var string
     */
    public $option1;
};
$object::presetOptions('nameOfPreset', [
    'option1' => 'value1'
]);
$object->init(['presetName' => 'nameOfPreset']);
$object->option1 === 'value1';
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~13 days

Recently: every ~24 days

Total

59

Last Release

1948d ago

Major Versions

v1.4.3 → v2.0.02019-02-02

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9679597?v=4)[Yaroslav](/maintainers/mrself)[@mrself](https://github.com/mrself)

---

Top Contributors

[![mrself](https://avatars.githubusercontent.com/u/9679597?v=4)](https://github.com/mrself "mrself (137 commits)")

---

Tags

dependency-injectionoptionspackagephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrself-options/health.svg)

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

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k245.4M24.0k](/packages/friendsofphp-php-cs-fixer)[symfony/rate-limiter

Provides a Token Bucket implementation to rate limit input and output in your application

27051.7M257](/packages/symfony-rate-limiter)[akeneo/pim-community-dev

Akeneo PIM, the future of catalog management is open!

1.0k624.1k86](/packages/akeneo-pim-community-dev)[symfony/ldap

Provides a LDAP client for PHP on top of PHP's ldap extension

1367.9M56](/packages/symfony-ldap)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

53675.5k17](/packages/solspace-craft-freeform)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9417.2k58](/packages/open-dxp-opendxp)

PHPackages © 2026

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