terabytesoftw/events-user

Events User Core

dev-master / 1.0.x-dev 2019-07-24 23:02 UTC

This package is auto-updated.

Last update: 2024-11-25 10:35:30 UTC


README

Events User Core

Unstable Version Build Status Build Status Build Status Code Quality Code Intelligence Status Maintainability


DIRECTORY STRUCTURE:

config/             contains application configurations
src/                contains source files
tests/              contains tests codeception for the web application
vendor/             contains dependent 3rd-party packages

REQUIREMENTS:

  • The minimum requirement by this project template that your Web server supports:
    • PHP 7.2 or higher.

INSTALLATION:

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

You can then install this extension using the following command composer:

composer require terabytesoftw/events-user '^1.0@dev'

or add composer.json:

"terabytesoftw/events-user":"^1.0@dev"

USAGE:

Event Class: UserEvent.php

<?php

namespace terabytesoft\events\user;

use yii\base\Event;

/**
 * Class UserEvent
 *
 * User events applications
 **/
class UserEvent extends Event
{
    /**
     * event is triggered before blocking existing user
     * triggered with \terabytesoft\events\user\UserEvent
     **/
    const BEFORE_BLOCK = '\terabytesoft\events\user\UserEvent::BEFORE_BLOCK';

    /**
     * event is triggered after blocking existing user
     * triggered with \terabytesoft\events\user\UserEvent
     **/
    const AFTER_BLOCK = '\terabytesoft\events\user\UserEvent::AFTER_BLOCK';

    /**
     * @var object $form
     */
    private $form;

    /**
     * getForm
     */
    public function getForm(): object
    {
        return $this->form;
    }

    /**
     * setForm
     */
    public function setForm(object $form): void
    {
        $this->form = $form;
    }
}

Controller/Model: Example

<?php

Use yii\base\Event

Class MockControler extend controller
{
    /**
     * actionBlock
     */
    public function actionBlock(): void
    {
        $this->event = new UserEvent([
            'form' => $this->model,
        ]);

        $this->trigger(UserEvent::BEFORE_BLOCK, $this->event);
        $this->trigger(UserEvent::AFTER_BLOCK, $this->event);
    }
}

Define actions Event::on in config/events/MockEvents.php

<?php

Use yii\base\Event

Event::on(MockController::class, UserEvent::BEFORE_BLOCK, function ($event) {
    // Actions here
    // $event->form Model pass
    // $event->name Event Name
});

Event::on(MockController::class, UserEvent::AFTER_BLOCK, function ($event) {
    // Actions here
    // $event->form Model pass
    // $event->name Event Name
});

Config events composer-plugin: composer.json

"extra": {
    "config-plugin": {
        "defines": [
            "config/events/MockEvents.php"
        ]
    }
},
$composer du

RUN TESTS CODECEPTION:

// download all composer dependencies root project
$ composer update --prefer-dist -vvv

// run all tests with code coverage
$ vendor/bin/codecept run unit --coverage-xml

WEB SERVER SUPPORT:

  • Apache.
  • Nginx.
  • OpenLiteSpeed.

DOCUMENTATION STYLE GUIDE:

Style CI Documentation PSR2.

LICENCE:

License YiiFramework Total Downloads StyleCI