Download the PHP package slashequip/attempt without Composer

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

Attempt

Attempt is a simple, fluent class for attempting to run code multiple times whilst handling exceptions. It attempts to mimic PHPs built-in try/catch syntax where possible but sprinkles in some additional magic on top.

Installation

Attempt has been added to packagist and can be installed via composer:

Getting an instance

Depending on your preference you can grab an Attempt instance in a couple of ways:

Building your Attempt

Once you have your instance you can begin to build your Attempt.

Try

This is the only required method, the try method accepts a callable argument, the code that you want to run.

Then Return

You may have noticed in the example above the method thenReturn, this method is what tells the Attempt to run. It will also return the value you return from the callable you pass to the try method.

There is also a then method, this too accepts a callable which is executed and passed the value returned by your try callable.

If it's your kind of jam, an attempt is also invokable which means at any point you can invoke the Attempt and it will run.

Times

You can set the amount of times the Attempt should be made whilst an exception is being encountered see catch.

Catch

The catch method allows you to define exceptions you are expecting to encounter during the attempts, when exceptions have been passed to the catch method the Attempt will throw any other types of exceptions it comes across early rather than performing all attempts.

The catch method can be called multiple times to add multiple expected exceptions.

If you do not provide any expected exception via the catch method then the Attempt will ignore all exceptions until all attempts have been made.

The catch method also allows you to define a callback that will be called when the specified exception is eventually thrown. This can be useful for error logging or you could also return a default value if your code is to continue.

No Throw

Attempt can be configured to never throw exceptions, there are situations when you want to execute some code but still continue with the rest of your logic. For these situations you can use noThrow.

Finally

The finally method allows you to run a callback at the end of the attempt no matter the result, whether the attempt was successful or an exception was thrown the finally callback will always be run.

Wait Between

The waitBetween method takes an integer indicating the desired number of milliseconds to wait between attempts. The pause happens before the code runs but does not delay the starting of the Attempt.

Example use case


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

Loading the files please wait ....