protected function registerEventsTo(EntityCollection $collection, $cid)
    {
        $collection->setId($cid);
        $collection->getEmitter()
            ->addListener(
                EntityAdded::ACTION_ADD,
                [$this, 'updateCollection']
            );
        $collection->getEmitter()
            ->addListener(
                EntityRemoved::ACTION_REMOVE,
                [$this, 'updateCollection']
            );
        $entity = $this->repository->getEntityDescriptor()->className();
        Orm::addListener(
            $entity,
            Delete::ACTION_AFTER_DELETE,
            function (Delete $event) use ($collection) {
                $collection->remove($event->getEntity());
            },
            EmitterInterface::P_HIGH
        );
        return $this;
    }
protected function registerEventsTo(EntityCollection $collection, $cid)
    {
        $collection->setId($cid);
        $collection->getEmitter()
            ->addListener(
                EntityAdded::ACTION_ADD,
                [$this, 'updateCollection']
            );
        $collection->getEmitter()
            ->addListener(
                EntityRemoved::ACTION_REMOVE,
                [$this, 'updateCollection']
            );
        $entity = $this->repository->getEntityDescriptor()->className();
        Orm::addListener(
            $entity,
            Delete::ACTION_AFTER_DELETE,
            function (Delete $event) use ($collection) {
                $collection->remove($event->getEntity());
            },
            EmitterInterface::P_HIGH
        );
        return $this;
    }
protected function registerEventsTo ( EntityCollection $ collection , $ cid ) { $ collection -> setId ( $ cid ) ; $ collection -> getEmitter ( ) -> addListener ( EntityAdded :: ACTION_ADD , [ $ this , 'updateCollection' ] ) ; $ collection -> getEmitter ( ) -> addListener ( EntityRemoved :: ACTION_REMOVE , [ $ this , 'updateCollection' ] ) ; $ entity = $ this -> repository -> getEntityDescriptor ( ) -> className ( ) ; Orm :: addListener ( $ entity , Delete :: ACTION_AFTER_DELETE , function ( Delete $ event ) use ( $ collection ) { $ collection -> remove ( $ event -> getEntity ( ) ) ; } , EmitterInterface :: P_HIGH ) ; return $ this ; }
Register entity events listeners for the provided collection

@param EntityCollection $collection
@param string $cid

@return self
Register entity events listeners for the provided collection