MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/www/sabbry/vendor/tiagosampaio/event-observer/src/Observer/ObserverAbstract.php
<?php

declare(strict_types = 1);

namespace TiagoSampaio\EventObserver\Observer;

use TiagoSampaio\EventObserver\EventInterface;

/**
 * Class ObserverAbstract
 *
 * @package TiagoSampaio\Event\Observer
 */
abstract class ObserverAbstract implements ObserverInterface
{
    /**
     * @var array
     */
    protected $bindEvents = [];
    
    /**
     * @param EventInterface $event
     */
    final public function execute(EventInterface $event)
    {
        if (!$this->canExecute($event)) {
            return;
        }
        
        $this->process($event);
    }
    
    /**
     * @param EventInterface $event
     */
    abstract protected function process(EventInterface $event);
    
    /**
     * @param EventInterface $event
     *
     * @return bool
     */
    protected function canExecute(EventInterface $event)
    {
        if (!$this->bind($event->getEventName())) {
            return false;
        }
        
        return true;
    }
    
    /**
     * @param string $eventName
     *
     * @return bool
     */
    private function bind($eventName)
    {
        return (bool) in_array($eventName, $this->bindEvents);
    }
}