1. Go to this page and download the library: Download ahmard/preact 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/ */
ahmard / preact example snippets
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]);
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' => '[email protected]'
]);
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';
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.