PHP code example of limingxinleo / swoft-entity-event

1. Go to this page and download the library: Download limingxinleo/swoft-entity-event 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/ */

    

limingxinleo / swoft-entity-event example snippets



namespace SwoftTest\Testing\Event;

use Swoft\Db\Model;
use Swoftx\EntityEvent\Annotation\EventListener;
use Swoftx\EntityEvent\EventInterface;
use SwoftTest\Testing\Entity\User;
use Swoft\Bean\Annotation\Bean;

/**
 * @Bean
 * @EventListener(User::class)
 */
class UserEventListener implements EventInterface
{
    public function beforeCreate(Model $model): Model
    {
        // Do something...
        return $model;
    }

    public function afterCreate(Model $model): Model
    {
        // Do something...
        return $model;
    }

    public function beforeUpdate(Model $model): Model
    {
        // Do something...
        return $model;
    }

    public function afterUpdate(Model $model): Model
    {
        // Do something...
        return $model;
    }