PHP Classes

PReact PHP Ask Confirmation before Action: Ask confirmation before actions they are executed

Recommend this page to a friend!
  Info   View files Documentation   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 This week: 1All time: 10,413 This week: 560Up
Version License PHP version Categories
preact 1.0.1The PHP License5PHP 5, Validation, Language
Description 

Author

This package can be used for asking confirmation before actions they are executed.

It provides an event handled and dispatcher class that can register event handling callback functions and invokes those functions when the event of that type is emitted.

The package also provides traits uses promises that can be used with classes that can check conditions to confirm that an action can be performed.

Innovation Award
PHP Programming Innovation award nominee
October 2020
Number 3
Sometimes applications need to perform delicate actions that may not be reversible. In this case it is better that the user is asked to confirm the actions before they are executed to avoid that the user regrets later.

This package can make it easier to implement action confirmation requests right before the requested action is about to happen.

Manuel Lemos
Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 23 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 229912 in Nigeria Nigeria
Week rank: 52 Up5 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 9x

Documentation

Preact

Performs action before-hand, confirms action execution.<br/> This program uses ReactPHP Promise for its promise implementation.

Installation

composer require ahmard/preact

Usage

  1. Event
  2. Preact

Event

An event system for simple event-driven programming.

use Preact\Event;

$event = new Event();

$event->on('user.created', function ($user){
    echo "User created: {$user['name']}";
});

$user = [
    'id' => 1,
    'name' => 'Admin'
];
$event->emit('user.created', [$user]);

You can use Preact\EventTrait trait directly in your class and have the functionality embedded in your code.

namespace App\User;

use Preact\EventTrait;

class User
{
    use EventTrait;
    
    public function create(array $userInfo)
    {
        //Save in DB
        $this->emit('created', [$userInfo]);
    }
}

$user = new User;

$user->on('created', function ($user){
    echo "User created: {$user['username']}\n";
});

$user->create([
    'username' => 'Admin',
    'email' => 'admin@test.local'
]);

Preact

Have confirmation before execution.

use React\Promise\PromisorInterface;
use Preact\PreactTrait;

class Animal
{
    use PreactTrait;
}

$animal = new Animal();

$animal->onPreact('can.create', function (PromisorInterface $promisor, $animalInfo){
    if($animalInfo['name'] == 'lion'){
        $promisor->resolve(true);
    }else{
        $promisor->reject(false);
    }
});

$animal->preact('can.create', ['lion'])
    ->then(function (){
        echo 'Animal creation allowed: lion';
    })
    ->otherwise(function (){
        echo 'Animal creation rejected: lion.\n';
    });

To see more use cases view examples.

Licence

Preact is MIT licenced.


  Files folder image Files  
File Role Description
Files folder imageexamples (3 files)
Files folder imagesrc (6 files)
Files folder imagetests (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Plain text file advance-preact.php Class Class source
  Plain text file simple-event.php Class Class source
  Plain text file simple-preact.php Class Class source

  Files folder image Files  /  src  
File Role Description
  Plain text file Event.php Class Class source
  Plain text file EventInterface.php Class Class source
  Plain text file EventTrait.php Class Class source
  Plain text file Preact.php Class Class source
  Plain text file PreactInterface.php Class Class source
  Plain text file PreactTrait.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file EventTest.php Class Class source
  Plain text file PreactTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:62
This week:1
All time:10,413
This week:560Up