Hi,

I have

abstract class BaseService extends Object implements BaseFacade {
  public $onPostSave;

  protected function _save ( BaseEntity $entity ) {
        $this -> onPreSave ( $entity );
        try {
            $newEntity = $this -> DAO -> save ( $entity );
        } ...
        $this -> onPostSave ( $newEntity );
        return $newEntity;
    }
}

class ResultVersionService extends BaseService implements ResultVersionFacade {
}

class ResultVersionListener extends Object implements Subscriber {
  public function getSubscribedEvents()
    {
        return [
            'services\ResultVersionService::onPostSave'
        ];
    }
}

So I want to listen on postSave of concrete service, not on abstract one. Is there a way to do it (easily)?

Thank for help

The simplest ways right now is to inject EventManager and dispatch the event manually.

abstract class BaseService extends Object implements BaseFacade
{
    private $evm;

    public function __construct(EventManager $evm)
    {
        $this->evm = $evm;
    }

    protected function doSave(BaseEntity $entity)
    {
        $this->evm->dispatchEvent(get_class($this) . '::onPreSave', new EventArgsList([$entity]));

        // ...

        $this->evm->dispatchEvent(get_class($this) . '::onPreSave', new EventArgsList([$entity]));

        return $newEntity;
    }

There will a be better way in the near future.

I suppose this has been solved recently.


You must first log in to participate in this discussion