Download the PHP package catpaw/unsafe without Composer

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

Install with

Control flow is king

I am of the opinion that control flow is one of the most important things to deal with as a programmer, it affects my thinking and at times it actually guides my problem solving process.

Managing errors should not break the flow in which I control my program, I shouldn't have to jump up and down around my file to catch a new exception introduced by a new function I just invoked 20 lines above.

Try/Catch

I found myself relying way too much on code like this

or even

The last one might make sense in theory, but in practice those exceptions might each mean something different, a different cause for an error.

The reality is that very often I lump those exceptions in together because I forget to manage them or because for some reason at 4 AM I decide on the spot "yes, I should let my IDE dictate my error management".

Try/catch error handling has been (probably) the most popular way to manage errors in php, and I think it still is a valid way of dealing with errors in a global scope.

I can't argue there is something nice about having one centralized place to manage all errors, but I don't want to be forced to approach error management all the time in that manner.

If you're anything like me you might prefer managing your error inline, directly at the source, so that you deal with it when it pops up and then you don't have to think about it anymore.

Unsafe

I have a solution.

Do not throw exceptions in your code, instead return your errors as Unsafe.

Use the ok() and error() functions to create Unsafe objects.

ok()

Return ok($value) whenever there are no errors in your program.

This function will create a new Unsafe with a valid $value and no error.

error()

Return error($error) whenever you encounter an error in your program and want to propagate it upstream.

This function will create a new Unsafe with a null $value and the given error.

Example

The following example tries to read the contents of a file while managing errors.

First I'm declaring all entities involved, classes and functions.

then

  1. open a file
  2. read its contents
  3. close the file

This code will print the contents of file.txt if all operations succeed.

Each time ->try($error) is invoked the Unsafe object tries to unwrap its value.\ If the Unsafe object contains an error, the value returned by ->try($error) resolves to null and the variable $error is assigned the contained error by reference.

anyError()

You can use anyError() to deal away with the repetitive snippet

Here's the same example but written using anyError()

The anyError() function takes a generator function and it consumes it step by step.

When the generator function yields an Error or an Unsafe containing an Error, the anyError function will stop executing the generator immediately and return a new Unsafe containing the given error.

Effectively, or yield $error acts like

On the other hand, if the result of ->try() is valid, the or <expression> is not executed and the generator keeps running until it reaches the next yield error statement, the next return statement or until the generator is consumed.

Matching

Since errors are results, you can actually match() them

or apply any sort of expression that you want inline.


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

Loading the files please wait ....