PHP code example of elephpant / trigger

1. Go to this page and download the library: Download elephpant/trigger 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/ */

    

elephpant / trigger example snippets



\ElePHPant\Trigger\Trigger;

//Like you can see down, it's possible receive four params
// 1 - Message Body, where you'ill put the own message to explicit for the member.
// 2 - Title (optional param) for you insert the title of message.
// 3 - You can record the field (optional param) of form for show for your member some message about those field.
// 4 - Normally plugins that you can utilize there's a time to show message in the screen, then you can define a default Timeout (default's 5000 miliseconds)

$trigger = new Trigger();
$trigger->success("Body of Message", "Title of Message", ["field_of_form"],3000);




\ElePHPant\Trigger\Trigger;
$trigger = new Trigger();

// There're 4 types trigger:

//::SUCCESS::
$trigger->success("A new member was added with Success", "Great!", null);

//::ERROR::
$trigger->error("Insert a valid e-mail!", "Whoopss", ["email"]);

//::WARNING::
$trigger->warning("Your password is so short!","Cation!",["password"]);

//::INFO::
$trigger->info("You need complete your profile!","Info!");


\ElePHPant\Trigger\Trigger;
$trigger = new Trigger();

// For default You can only show a unique error;
// But you can set a option to show several errors that your record in the Trigger Object
// For that You will change the uption Unique in the RENDER METHOD

//::SUCCESS:: UNIQUE
$trigger->success("A new member was added with Success", "Great!", null)->render();


//::ERROR:: SEVERAL ERRORS THAT YOU HAVE
$trigger->error("Your e-mail is invalid", "Bad!", ["email"]);
$trigger->error("Your password must have minimum 8 characters", "Bad!", ["password"]);
$trigger->render(false); //Here you Will have two errors for you show in the View for your User.



// You can abstract the behavior of the component like that

namespace MyApp;
use ElePHPant\Trigger\Trigger;

class Message extends Trigger
{
    public function danger(string $message, ?string $title = null, ?array $fields = null, int $timeOut = 5000):self
    {
            $this->setTrigger(__FUNCTION__, $message, $title, $fields, $timeOut);
            return $this;
    }
}

// And voilà, you have a new method, with another name, and you can do whatever. This is possible because this component was thought for implement in any project.



//You can send throw the Controller a response in json and your js can read and do anything

//From controller: 

echo json_encode(['response'=>$trigger->success('You need insert a valid e-mail!')->render()]);