PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Ahmad Mustapha  >  Simple PHP Promise Library  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: Simple PHP Promise Library
Register functions to call when conditions are met
Author: By
Last change:
Date: 1 year ago
Size: 954 bytes
 

Contents

Class file image Download

Simple Promise

A simple PHP promise library that works synchronously.

Note

Please note that this library cannot be used in Asynchronous projects, projects like ReactPHP or Amphp.

Installation

Make sure that you have composer installed Composer.

If you don't have Composer run the below command

curl -sS https://getcomposer.org/installer | php

Run the installation

composer require ahmard/simple-promise ^1.0

Usage

<?php
use SimplePromise\Deferred;

require 'vendor/autoload.php';

function test($number)
{
    $deferred = new Deferred();
    
    if ($number > 2){
        $deferred->resolve('Succeeded');
    }else{
        $deferred->reject('Failed');
    }
    
    return $deferred->promise();
}

test(1)->then(function ($data){
    echo $data;
})->otherwise(function ($error){
    echo $error;
});

Examples

For more information send a message to info at phpclasses dot org.