Skip to content

PubSub (event model)

Aleksey Ilyin edited this page Feb 22, 2024 · 6 revisions
Table of Contents

Overview
Events name
Example

Overview

Since version 2.0, all controllers raise an event when interacting with them.

SRC

/src/Application/PubSub.php

Events name

All events have their own name according to a given pattern: [layer]:[entity]{:[subentity]}:[action], where:
  1. layer - one of: auth, common, cup, plugin or api;
  2. entity - model name;
  3. subentity - sub model name;
  4. action - produced action (such as the list, add, edit, delete, and other login, register, send, upload).

Example: api:[entity]:create, api:[entity]:edit, plugin:order:payment, auth:user:logout, common:user:login, cup:catalog:attribute:create, cup:catalog:order:delete, common:file:upload, task:mail:send

Example

Take a look at the code in src/Application/Actions/Cup/Catalog/Category/CategoryUpdateAction.php:47
$this->container->get(\App\Application\PubSub::class)->publish('cup:catalog:category:edit', $category);

In plugin constructor:

$this
    ->subscribe(
        ['cup:catalog:data:import', 'cup:catalog:category:add', 'cup:catalog:category:edit', 'cup:catalog:category:delete', 'cup:catalog:product:add', 'cup:catalog:product:edit', 'cup:catalog:product:delete'],
        function (mixed $model) {
            // some action
        }
    )
Clone this wiki locally