Download the PHP package bosunski/results without Composer

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

Results

Results is a PHP simple (dependency-free) library that provides a set of helper functions and classes for handling optional values and results of operations. It is inspired by the Option and Result types in Rust. The implementation itself is based on the TypeScript implementation called ts-results.

Installation

You can install the library through Composer:

Usage

Demo

You can try the package in this Playground

Option

The Option type represents an optional value: every Option is either Some and contains a value, or None, and does not.

Result

The Result type is a type that represents either success (Ok) or failure (Err).

Helper Functions

The library provides a set of helper functions for creating Option and Result instances:

Examples

Optional values and results in PHP can be represented using the Option and Result types provided by the Results library. Here are some examples:

In the above examples:

Let's dive into more complex examples of using the Option and Result types in PHP.

Consider a scenario where we have a function that may or may not return a value. We can use the Option type to handle this uncertainty.

Now, let's consider a scenario where we have a function that can either succeed or fail. We can use the Result type to handle this.

In these examples, the Option and Result types provide a way to handle optional values and the results of operations in a safe and expressive manner.

The wrap Function

The wrap function is a utility function provided by the library. It is designed to handle operations that can throw an error. The wrap function executes a callable and returns its result wrapped in a Result object. If the callable function throws an exception, the wrap function catches it and returns an Err object containing the exception.

[!IMPORTANT] The wrap function will only catch instances of Throwable. If your function raises something like a fatal error it will not be caught by wrap.

Here's an example of how you might use the wrap function:

In this example, mightThrowException is a function that might throw an exception. We pass this function to wrap, which executes it, catch any error and wraps the result in a Result object. We then check if the result is an instance of Ok or Err and handle it accordingly.

The wrap function provides a safe and expressive way to handle operations that can throw errors, allowing you to focus on your application logic rather than error handling when you don't need to.

Contributing

Setting up the project

You can install development dependencies by running:

Running tests

License

This project is licensed under the MIT License.


All versions of results with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
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 bosunski/results contains the following files

Loading the files please wait ....