Simple PHP Promise Library: Register functions to call when conditions are met

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-08-09 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 64 All time: 9,746 This week: 333Up
Version License PHP version Categories
simple-promise 1.0The PHP License5PHP 5, Language
Description Author

This package can register functions to call when conditions are met.

It provides a promise class that can register one callback function to be called when a condition is true. It can also call another callback function to be called when the condition is false.

The package also provides a deferred class to register a new promise to evaluate the conditions again later.

Innovation Award
PHP Programming Innovation award nominee
August 2020
Number 3
A promise is a control structure that you can use in your code to define the actions to be executed when a condition is true, false, or needs to be evaluate later again while the condition status is not yet determined.

This package provides means to implement promises in PHP by evaluating conditions now or later using deferred promises.

Manuel Lemos
Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 6 packages by
Country: Nigeria Nigeria
Innovation award
Innovation award
Nominee: 3x

Details

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

  Files folder image Files  
File Role Description
Files folder image.idea (5 files)
Files folder imageexamples (2 files)
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  .idea  
File Role Description
  Accessible without login Plain text file misc.xml Data Auxiliary data
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file simple-promise.iml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file 1-simple.php Example Example script
  Accessible without login Plain text file 2-exception.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file Deferred.php Class Class source
  Plain text file Promise.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:64
This week:0
All time:9,746
This week:333Up

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