예제 #1
0
 public static function initializeObject($object, $parameter)
 {
     $result = '';
     if (method_exists($object, 'init')) {
         try {
             $namedParameters = new NamedParameters();
             $result = $namedParameters->callMethod($object, 'init', $parameter);
         } catch (\phmLabs\Components\NamedParameters\Exception $e) {
             throw new ConfigurationException('Unable to initialize object (' . get_class($object) . '). ' . 'Mandatory parameter "' . $e->getMissingParameter() . '" is missing.');
         }
     }
     return $result;
 }
예제 #2
0
 /**
  * This function is used to call all listeners. It stops processing if the $until parameter is true and the
  * event is processed.
  *
  * @param Event $event
  * @param array $namedParameters
  * @param boolean $until If this param is true the event/listener chain will stop if the vent is processed.
  */
 private function processEvent(EventInterface &$event, $until = false)
 {
     $finalParameters = $event->getParameters();
     $finalParameters['event'] = $event;
     foreach ($this->getListeners($event->getName()) as $listener) {
         $result = NamedParameters::call($listener, $finalParameters);
         if ($until === true && $event->isProcessed()) {
             return $result;
         }
     }
     return null;
 }
예제 #3
0
파일: Init.php 프로젝트: phmlabs/init
 public static function initialize($element)
 {
     if (!array_key_exists("class", $element)) {
         throw new \RuntimeException("the given array does not provide an element with 'class' as key");
     }
     $class = $element['class'];
     if (!class_exists($class)) {
         throw new \RuntimeException("No class with name " . $class . " found");
     }
     $object = new $class();
     if (method_exists($object, 'init')) {
         if (array_key_exists('parameters', $element)) {
             $parameters = array_merge($element['parameters'], self::$globalParameters);
         } else {
             $parameters = self::$globalParameters;
         }
         NamedParameters::call([$object, 'init'], $parameters);
     }
     return $object;
 }