Download the PHP package skd/result without Composer

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

The Result object

This package allows you to work with the results of operations, including errors, in an object-oriented style, without using exceptions. For example, when using the 'Always valid domain model' approach. Result object allows you to accumulate errors and return them all at once (Notification pattern is inside). At the same time, the code becomes more understandable and logical.

Installation

Result

The Result class is an immutable generic class (using @template annotation) with 2 states: Ok and Error. The OK state means that there are no errors inside and there is some value (success operation result). The Error state means that an error or several errors were received during the operation.

Use @return Result<type_or_class> annotation to tell the IDE and static analysis tool what type value is inside;

Ok state

Use static method Result::ok to return success operation result with some value inside

Use method Result::getValue(): T to get the value. Note that calling this method on Error state will throw an exception. To prevent that you have to check the result state by calling one of methods Result::isOk(): bool or Result::isError(): bool before.

Error state

Use static method Result:error(Notification $errors) to return result with an error (errors). The non-empty Notification object must be passed as an argument. Passing an empty Notification object (no errors inside) will throw an exception.

Use method Result::getErrors(): Notification to get an error (errors). Note that calling that method on Ok state will throw an exception. You can't change Notification object after Result object is initialized

Notification

Notification class is a Notification pattern realisation. It can be initialized in two ways: as an empty list or a list with one error inside

Use method Notification::hasErrors(): bool to check if there are error/errors inside the notification object

Use method Notification::hasError(Error $error): bool to check if the specific error is inside the notification object. It can be useful in Unit tests.

Errors Accumulating

Errors can be accumulated in a Notification object.

Use Notification::addError(Error $error): void to add some error in the list

Notification objects can be merged as well. It can be useful when you have to accumulate two or more results with errors. Note that only left object will be changed.

Example:

Some Value Object class

You can replace with static factory:

Unit tests


All versions of result 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 skd/result contains the following files

Loading the files please wait ....