PHPackages                             nowise/uup-application-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. [HTTP &amp; Networking](/categories/http)
4. /
5. nowise/uup-application-options

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nowise/uup-application-options
==============================

Uniform CLI command line and HTTP request options.

1.0.6(4y ago)0182Apache-2.0PHPPHP &gt;=7.4

Since Dec 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nowisesys/uup-application-options)[ Packagist](https://packagist.org/packages/nowise/uup-application-options)[ Docs](https://nowise.se/oss/uup/application-options)[ RSS](/packages/nowise-uup-application-options/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (8)Used By (2)

UUP-APPLICATION-OPTIONS
=======================

[](#uup-application-options)

Supports transparent/uniform handling of runtime options from CLI command and HTTP request.

This package supports short/long options, other options and reading password from terminal (masked echo output). For HTTP request options, an optional filter can be applied.

### USAGE:

[](#usage)

In your command action class, define a method that checks whether to return command line options (CLI) or from request option (HTTP).

```
private function getApplicationOptions(): ApplicationOptionsInterface
{
    if (php_sapi_name() == 'cli') {
        return new CommandLineOptions();
    } else {
        return new HttpRequestOptions();
    }
}
```

Calling `getApplicationOptions` will provide uniform access to application options, whether these come from command line or the HTTP request. From your application perspective the origin of options is transparent.

From within the application, a number of convenient methods can be used for checking if options was passed and retrieve them with type safety.

```
public function setup()
{
    $this->options = $this->getApplicationOptions();
}

public function execute(): void
{
    //
    // Example of setting defaults:
    //
    if ($this->options->isMissing('user')) {
        $this->options->setOption('user', 'adam');
    }

    //
    // Take action if option is defined:
    //
    if ($this->options->hasOption('email')) {
        $this->sendEmail($this->options->getString('email'));
    }
}
```

A number of other getters exist, for example for boolean, float and integer values. These takes a second default value that is returned of option is missing.

### ORIGIN:

[](#origin)

If origin matters, it can be checked:

```
if ($this->options->getOrigin() == ApplicationOptionsInterface::ORIGIN_HTTP) {
    throw new RuntimeException("This action can't be run from a HTTP context");
}
```

### OPTION ALIAS:

[](#option-alias)

For command line options, the default behavior is to return options by stripping leading dashes ('-'). To support short command options mapped to long options, pass a mapping array.

```
private function getApplicationOptions(): ApplicationOptionsInterface
{
    if (php_sapi_name() == 'cli') {
        return new CommandLineOptions([
            '-f' => 'file',
            '-U' => 'user'
        ]);
    } else {
        return new HttpRequestOptions();
    }
}
```

These two short option will now be an alias for their equivalent long option. Some builtin aliases are implicit handled for command line options. These short options are:

- -h =&gt; help
- -V =&gt; version
- -d =&gt; debug
- -v =&gt; verbose
- -q =&gt; quiet

These are processed before user defined mappings, making it possible to easily redefine the builtin mapping.

### OPTION VALUES:

[](#option-values)

Option values are any value after the equal character ('='). For options without a value, the option key will be read having boolean true as its value.

### DASHES:

[](#dashes)

Processing of command line options (CLI) will strip leading dashes and use the remaining string as the command option key.

### OPTION FILTERING:

[](#option-filtering)

Command line options are considered safe. For HTTP request, it's possible to pass an array of sanitation filter to be applied.

```
private function getApplicationOptions(): ApplicationOptionsInterface
{
    if (php_sapi_name() == 'cli') {
        return new CommandLineOptions();
    } else {
        return new HttpRequestOptions(
            new HttpRequestFilter([
                'user'  => FILTER_SANITIZE_STRING,
                'email' => FILTER_SANITIZE_EMAIL
            ])
        );
    }
}
```

The default behavior is to not filter HTTP request options. For larger applications, some framework for purify HTML input might be used that could be wrapped in a class that implements the `FilterInterface` and used instead of passing an instance of the `HttpRequestFilter` class.

### BOOLEANS:

[](#booleans)

Special treatment of boolean options are implemented. For example, option values "1", "true", "on" and "yes" yields true. Analogous "0", "false", "off" and "no" yields false.

Example: Call `getBoolean` to have the value for filter option evaluated as boolean.

```
$this->options->getBoolean("filter");
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% 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 ~9 days

Total

7

Last Release

1566d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/051c93d5c76da455715b999de080c10df538ce46843177f3b1779c235fe4aaff?d=identicon)[nowise](/maintainers/nowise)

---

Top Contributors

[![nowisesys](https://avatars.githubusercontent.com/u/35581658?v=4)](https://github.com/nowisesys "nowisesys (15 commits)")[![andlov](https://avatars.githubusercontent.com/u/69963530?v=4)](https://github.com/andlov "andlov (9 commits)")

---

Tags

httpclicommanduupapplication-options

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nowise-uup-application-options/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.1k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[psr/link

Common interfaces for HTTP links

2.5k144.1M69](/packages/psr-link)[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M253](/packages/rmccue-requests)[league/uri

URI manipulation library

1.1k206.4M276](/packages/league-uri)

PHPackages © 2026

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