elephpant/trigger

Trigger 是一种非常简单的方式来通过高度可定制的消息与您应用程序的用户进行通信

1.0.4 2021-11-01 18:42 UTC

This package is auto-updated.

Last update: 2024-09-29 05:37:24 UTC


README

Maintainer Source Code PHP from Packagist Latest Version Software License Build Quality Score Total Downloads

Trigger 是一种非常简单的方式来通过高度可定制的消息与您应用程序的用户进行通信。

Trigger 是一种非常简单的方式来通过高度可定制的消息与您应用程序的用户进行通信。

亮点

  • 极其简单
  • 灵活
  • 可以为视图界面发送消息
  • Composer 准备就绪且符合 PSR-2 规范(Pronto para o composer e compatível com PSR-2)

安装

通过 Composer 提供引用

"elephpant/trigger": "*"

或运行

composer require elephpant/trigger

文档

有关如何使用详细信息,请参阅组件目录中的示例文件夹。在那里您将找到该组件的示例用法。它的工作方式如下

有关如何使用详细信息,请参阅组件目录中的示例文件夹。在那里您将找到该组件的示例用法。它的工作方式如下

很简单。

<?php
require __DIR__ . "/vendor/autoload.php";

use \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);

类型

<?php
require __DIR__ . "/vendor/autoload.php";

use \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!");

单个错误或多个错误

<?php
require __DIR__ . "/vendor/autoload.php";

use \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.

继承和多态

<?php
// 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.

Trigger 是否与您的 JavaScript 通信

<?php
//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()]);
//With JS (I'll utilize the jQuery Library for example) you can:
$(function(){
    $('form').submit(function(e){
        e.preventDefault();
        var form = $(this);
        var action = form.attr('action');

        $.post(action, function(response){
        
            if(response.message){
                var field = form.find("[name="+response.field+"]");
                field.addClass('is-invalid');
                field.parents('.form-group').append(`<div class="invalid-feedback">${response.message}</div>`);
            }
        }, 'json');
    });
});

贡献

有关详细信息,请参阅CONTRIBUTING

支持

安全:如果您发现任何与安全相关的问题,请通过电子邮件sergiodanilojr@hotmail.com联系,而不是使用问题跟踪器。

如果您发现任何与安全相关的问题,请通过电子邮件sergiodanilojr@hotmail.com联系,而不是使用问题跟踪器。

谢谢

致谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅许可文件