Download the PHP package brimmar/phpresult without Composer

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

PHP Result Type Documentation

This documentation covers the implementation of a Rust-like Result Type for PHP. The Result type is used for returning and propagating errors. It has two variants: Ok, representing success and containing a value, and Err, representing error and containing an error value.

Table of Contents

  1. Result Interface
  2. Usage
  3. Methods
  4. Complementary Packages
  5. Static Analysis
  6. Contributing
  7. Security Vulnerabilities
  8. License

Result Interface

The Result interface defines the contract for both Ok and Err classes.

Usage

First Example

Second Example

Third Example

Fourth Example

Methods

isOk(): bool

Returns true if the result is Ok.

Example:

isOkAnd(callable $fn): bool

Returns true if the result is Ok and the value inside of it matches a predicate.

Example:

isErr(): bool

Returns true if the result is Err.

Example:

isErrAnd(callable $fn): bool

Returns true if the result is Err and the value inside of it matches a predicate.

Example:

ok(?string $className): mixed

Converts from Result<T, E> to Option<T>.

Example:

err(?string $className): mixed

Converts from Result<T, E> to Option<E>.

Example:

unwrap(): mixed

Returns the contained Ok value. Throws an exception if the value is an Err.

Example:

expect(string $msg): mixed

Returns the contained Ok value. Throws an exception with a provided message if the value is an Err.

Example:

expectErr(string $msg): mixed

Returns the contained Err value. Throws an exception with a provided message if the value is an Ok.

Example:

flatten(): Result

Converts from Result<Result<T, E>, E> to Result<T, E>.

Example:

intoErr(): mixed

Returns the contained Err value. Throws an exception if the value is an Ok.

Example:

intoOk(): mixed

Returns the contained Ok value. Throws an exception if the value is an Err.

Example:

iter(): Iterator

Returns an iterator over the possibly contained value.

Example:

unwrapOr(mixed $default): mixed

Returns the contained Ok value or a provided default.

Example:

unwrapOrElse(callable $fn): mixed

Returns the contained Ok value or computes it from a closure.

Example:

map(callable $fn): Result

Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched.

Example:

mapErr(callable $fn): Result

Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched.

Example:

mapOr(mixed $default, callable $fn): mixed

Returns the provided default (if Err), or applies a function to the contained value (if Ok).

Example:

mapOrElse(callable $default, callable $fn): mixed

Maps a Result<T, E> to U by applying fallback function default to a contained Err value, or function fn to a contained Ok value.

Example:

inspect(callable $fn): self

Calls the provided closure with a reference to the contained value (if Ok).

Example:

inspectErr(callable $fn): self

Calls the provided closure with a reference to the contained error (if Err).

Example:

and(Result $res): Result

Returns res if the result is Ok, otherwise returns the Err value of self.

Example:

andThen(callable $fn): Result

Calls fn if the result is Ok, otherwise returns the Err value of self.

Example:

or(Result $res): Result

Returns self if it is Ok, otherwise returns res.

Example:

orElse(callable $fn): Result

Calls fn if the result is Err, otherwise returns the Ok value of self.

Example:

transpose(?string $noneClassName, ?string $someClassName): mixed

Transposes a Result of an Option into an Option of a Result.

Example:

match(callable $Ok, callable $Err): mixed

Matches the result and returns a value based on the provided patterns.

Example:

Complementary Packages

This package works well with the PHP Option Type package, which implements the Option Type. Some methods in this package, such as transpose, depend on the Option Type implementation.

PhpOption

Static Analysis

We recommend using PHPStan for static code analysis. This package includes custom PHPStan rules to enhance type checking for Result types. To enable these rules, add the following to your PHPStan configuration:

Contributing

Please see CONTRIBUTING.md for details.

Security Vulnerabilities

Pleas review our security policy on how to report security vulnerabilities.

License

Please see LICENSE.md for more information.


All versions of phpresult with dependencies

PHP Build Version
Package Version
Requires php Version >=8.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 brimmar/phpresult contains the following files

Loading the files please wait ....