PHP code example of activecollab / promises

1. Go to this page and download the library: Download activecollab/promises library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

activecollab / promises example snippets




use ActiveCollab\DatabaseConnection\Connection\MysqliConnection;

$mysqli_link = new \MySQLi('localhost', 'root', '', 'activecollab_promises_test');

if ($mysqli_link->connect_error) {
    throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $mysqli_link->connect_error);
}

$mysqli_connection = new MysqliConnection($mysqli_link);

$promises = new Promises($this->connection);

// Print promise signature
$promise = $promises->create();

print $promise->getSinature() . "\n";
print (string) $promise . "\n"; // __toString() is available

// Default promise status
$promise = $promises->create();

$promises->isFulfilled($promise); // false
$promises->isRejected($promise);  // false
$promises->isSettled($promise);   // false

// Promise fulfillment
$promise = $promises->create();

$promises->fulfill($promise);

$promises->isFulfilled($promise); // true
$promises->isRejected($promise);  // false
$promises->isSettled($promise);   // true

// Promise rejection
$promise = $promises->create();

$promises->reject($promise);

$promises->isFulfilled($promise); // false
$promises->isRejected($promise);  // true
$promises->isSettled($promise);   // true