/**
  * Register your event
  * @param string $eventName
  * @param $className
  * @param int $priority
  * @param bool $queued
  */
 public function register($eventName, $className, $priority = 0, $queued = false)
 {
     $eventName = $this->getDefaultEventName() . $eventName;
     LoggerSphring::getInstance()->debug(sprintf("Registering event '%s' for class '%s'", $eventName, $className));
     $this->registers[$eventName] = $className;
     $this->sphringEventDispatcher->addListener($eventName, array($this, 'onEvent'), $priority, $queued);
 }
Exemple #2
0
 /**
  *
  */
 public function bootFromComposer()
 {
     $this->composerManager->setExtender($this->sphringEventDispatcher->getSphring()->getExtender());
     $this->composerManager->setRootProject($this->sphringEventDispatcher->getSphring()->getRootProject());
     $this->composerManager->loadComposer();
     $this->sphringAnnotationReader->initReader();
 }
 /**
  * Dispatch events
  * @param \Reflector $reflector
  * @param $eventNameBase
  */
 private function dispatchEventForAnnotation(\Reflector $reflector, $eventNameBase)
 {
     $annotationReader = $this->getSphringEventDispatcher()->getSphringBoot()->getSphringAnnotationReader();
     if ($reflector instanceof \ReflectionClass) {
         $annotationsArray = $annotationReader->getClassAnnotations($reflector);
     } else {
         $annotationsArray = $annotationReader->getMethodAnnotations($reflector);
     }
     if (empty($annotationsArray)) {
         return;
     }
     $toReturn = null;
     foreach ($annotationsArray as $annotation) {
         $eventName = $eventNameBase . strtolower(ClassName::getShortName($annotation));
         $event = new EventAnnotation();
         $event->setData($annotation);
         $event->setBean($this->bean);
         $event->setReflector($reflector);
         $event->setMethodArgs($this->methodArgs);
         $event->setName($eventName);
         $this->sphringEventDispatcher->dispatch($eventName, $event);
         $this->methodArgs = $event->getMethodArgs();
         if ($annotation != $event->getData()) {
             $toReturn = $event->getData();
         }
     }
     $this->toReturn = $toReturn;
 }
Exemple #4
0
 /**
  * @param string $propertyKey
  * @param mixed $propertyValue
  * @throws \Arthurh\Sphring\Exception\BeanException
  * @return AbstractBeanProperty
  */
 protected function getPropertyFromEvent($propertyKey, $propertyValue)
 {
     if (!isset($propertyValue)) {
         throw new BeanException($this, "property not valid");
     }
     $event = new EventBeanProperty();
     $event->setData($propertyValue);
     $eventName = SphringEventEnum::PROPERTY_INJECTION . $propertyKey;
     $event->setName($eventName);
     $event = $this->sphringEventDispatcher->dispatch($eventName, $event);
     if (!$event instanceof EventBeanProperty) {
         throw new BeanException($this, "event '%s' is not a '%s' event", get_class($event), EventBeanProperty::class);
     }
     return $event->getBeanProperty();
 }
Exemple #5
0
 public function setComposerLockFile($composerLockFile)
 {
     $composerManager = $this->sphringEventDispatcher->getSphringBoot()->getComposerManager();
     $composerManager->setComposerLockFile($composerLockFile);
 }