承接 josephlavin/local-eventing 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josephlavin/local-eventing

Composer 安装命令:

composer require josephlavin/local-eventing

包简介

In object eventing execution

README 文档

README

A simple php trait that allows for execution of local methods in an eventing like fashion. Add methods to a class using this trait following a naming convention and they will be executed when the local event is fired.

use josephlavin\localEventing\LocalEventing;

class dummy
{
    use LocalEventing;
    
    public function save()
    {
        // do your saving logic...
        $this->fireLocalEvent('saved');
    }

    protected function __onLocalEvent_saved_send_notification()
    {
        // Logic here to send notification...
    }

    protected function __onLocalEvent_saved_log_event()
    {
        // Logic for logging here...
    }
}

Event Listener Method Naming Convention

All event listener methods must be named in this fashion: __onLocalEvent_[event]_[description]()

  • __onLocalEvent_ : namespace for the local eventing system
  • [event]: the same string given to $this->fireLocalEvent('event')
  • [description]: a simple description of what this method does

Installation

$ composer require josephlavin/local-eventing

Use Case

Lets say we have a basic model type class which fires local events:

class BaseModel
{
    use LocalEventing;

    public function __construct()
    {
        $this->fireLocalEvent('created');
    }

    public function insert()
    {
        $this->fireLocalEvent('preInsert');
        // the insert logic...
        $this->fireLocalEvent('postInsert');
    }
}

We can create another trait that relies on the LocalEventing trait and adds __onLocalEvent__ methods. Notice how this trait has an abstract method _require_trait_LocalEventing. This serves as a reminder to the developer that this trait relies on the LocalEventing trait to work properly.

trait UuidPrimaryKey
{
    // reminder that we must also use LocalEventing Trait
    abstract protected function _require_trait_LocalEventing();

    protected function __onLocalEvent_preInsert_populate_uuid()
    {
        // generate and set a uuid primary key here...
    }
}

Now any models (that extend base model) can use the UuidPrimaryKey trait and gain that functionality.

class MyModel extends BaseModel
{
    use UuidPrimaryKey;
}

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固