Download the PHP package ekiwok/option without Composer

On this page you can find all versions of the php package ekiwok/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

PHP Option Build Status

Option is a value that might or might not be present. In other words it's elegant alternative to throwing an exception or allowing method to return null. It allows for fluent chaining method calls.

Instead of either:

Just have:

Allow null approach:

Option approach:

In contrary to other libraries this one implements separate Option for each scalar type and allows registering custom Options for objects. It's the closest to Java templates we can get and enforces strict type checking.

So if you prefer strict type checking over having a few opcodes less, you can enforce:

Optional::Some wraps each value to correct Option class:

Installation

With composer: composer require ekiwok/option

Interface

All scalar options enforce that methods get, orElse, orElseGet, orElseThrow returns the same scalar.

So it's not possible to orElse float from OptionString:

The only exception is Optional which does not enforce types.

Important thing to notice is that when you map Option which is None it will return Optional.

This is because there is no reasonable way to guess what should be the type of the value returned by a $supplier. In Some we are able to wrap accordingly to the type of the returned value.

On top of that you probably do not care about mapping when you're dealing with None because all further mappings will also return None.

But if you really want to ensure that, for example, orElseGet $supplier returns value of correct type you might provide expected type as another map parameter:

Custom mappings

Simply register custom mappings:

Any

If you don't want to get specific type like, for example, OptionString you can wrap $value into Any

Autogenerating options

There is experimental bin/generator.php for autogenerating custom Option classes.

It accepts full class name (including namespace) as first argument and optionally desired namespace as second argument (if not provided default namespace is class namespace prefixed with autoload).

So to generate OptionDateTime one could do:

vendor/ekiwok/opion/bin/generator.php \DateTime > ./autogenerated/OptionDateTime.php


All versions of option with dependencies

PHP Build Version
Package Version
No informations.
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 ekiwok/option contains the following files

Loading the files please wait ....