Download the PHP package aphonix/option without Composer

On this page you can find all versions of the php package aphonix/option. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package option

๐Ÿฆ€ Rust-style Option for PHP ๐Ÿ˜

A lightweight, zero-dependency implementation of Rust's Option for PHP 7.1+. This library brings functional programming patterns to PHP, helping you handle optional values explicitly and write more expressive code.

โœจ Features

๐Ÿš€ Installation

You can install the package via Composer:

๐Ÿ“– Quick Start

Basic Usage

Some(null) is allowed and represents a present value whose payload is null. Use None() when the value is absent.

Functional Chaining

Avoid defensive is_null() nesting with monad-style chaining:

Advanced: and_then (FlatMap)

Use and_then when your transformation closure returns an Option itself:

๐Ÿ›  API Reference

Check Methods

Method Description
is_some(): bool Returns true if the option is a Some value.
is_none(): bool Returns true if the option is a None value.
is_some_and(callable $f): bool Returns true if the option is Some and the value inside matches the predicate.

Unwrapping Methods

Method Description
unwrap() Returns the inner value. Throws an Exception (Panic) if the value is None.
expect(string $msg) Returns the inner value. Throws an Exception with a custom message if the value is None.
unwrap_or($default) Returns the inner value if it exists, otherwise returns the provided default.
unwrap_or_else(callable $f) Returns the inner value if it exists, otherwise returns the result of the closure.

Transformation & Filtering

Method Description
map(callable $f): Option Maps an Option to Option by applying a function to the contained value.
map_or($default, callable $f) Returns the provided default result, or applies a function to the contained value.
filter(callable $f): Option Returns None if the option is Some and the closure returns false.
and_then(callable $f): Option Returns None if the option is None, otherwise calls the closure with the value and returns the result.

Logical Operations

Method Description
and(Option $optB): Option Returns None if the option is None, otherwise returns $optB.
or(Option $optB): Option Returns the option if it contains a value, otherwise returns $optB.
xor(Option $optB): Option Returns Some if exactly one of self, $optB is Some, otherwise returns None.

๐Ÿงช Testing

This project uses PHPUnit to verify the core behavior:

๐Ÿ“„ License

The MIT License (MIT). Please see the License File for more information.


All versions of option with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aphonix/option contains the following files

Loading the files please wait ...