예제 #1
0
 public function run(Sabel_Bus_Config $config)
 {
     foreach ($config->getProcessors() as $name => $className) {
         $this->addProcessor(new $className($name));
     }
     foreach ($config->getConfigs() as $name => $className) {
         $this->setConfig($name, new $className());
     }
     $this->interfaces = $config->getInterfaces();
     $processorList = $this->processorList;
     $logging = $this->logging = $config->isLogging();
     try {
         while ($processor = $processorList->next()) {
             $this->beforeEvent($processor->name);
             if ($logging) {
                 l("Bus: execute " . $processor->name);
             }
             $processor->execute($this);
             $this->afterEvent($processor->name);
         }
         $processorList->first();
         while ($processor = $processorList->next()) {
             if ($logging) {
                 l("Bus: shutdown " . $processor->name);
             }
             $processor->shutdown($this);
         }
         return $this->get("result");
     } catch (Exception $e) {
         $msg = get_class($e) . ": " . $e->getMessage() . PHP_EOL . "At: " . date("r") . PHP_EOL . PHP_EOL . Sabel_Exception_Printer::printTrace($e, PHP_EOL, true);
         l(PHP_EOL . $msg, SBL_LOG_ERR);
         if ((ENVIRONMENT & DEVELOPMENT) > 0) {
             echo nl2br($msg);
         }
     }
 }
예제 #2
0
파일: Bus.php 프로젝트: reoring/sabel
 public function run(Sabel_Bus_Config $config)
 {
     foreach ($config->getProcessors() as $name => $className) {
         $this->addProcessor(new $className($name));
     }
     foreach ($config->getConfigs() as $name => $className) {
         $this->setConfig($name, new $className());
     }
     $this->interfaces = $config->getInterfaces();
     $logging = $config->isLogging();
     try {
         $logger = Sabel_Logger::create();
         $processorList = $this->processorList;
         while ($processor = $processorList->next()) {
             $processorName = $processor->name;
             $beforeEvents = $this->beforeEvent;
             if (isset($beforeEvents[$processorName])) {
                 foreach ($beforeEvents[$processorName] as $event) {
                     if ($logging) {
                         $logger->write("Bus: beforeEvent " . $event->object->getName() . "::" . $event->method . "()");
                     }
                     $event->object->{$event->method}($this);
                 }
             }
             if ($logging) {
                 $logger->write("Bus: execute " . $processor->name);
             }
             $processor->execute($this);
             $afterEvents = $this->afterEvent;
             if (isset($afterEvents[$processorName])) {
                 foreach ($afterEvents[$processorName] as $event) {
                     if ($logging) {
                         $logger->write("Bus: afterEvent " . $event->object->getName() . "::" . $event->method . "()");
                     }
                     $event->object->{$event->method}($this);
                 }
             }
         }
         $processorList->first();
         while ($processor = $processorList->next()) {
             if ($logging) {
                 $logger->write("Bus: shutdown " . $processor->name);
             }
             $processor->shutdown($this);
         }
         return $this->get("result");
     } catch (Exception $e) {
         $message = get_class($e) . ": " . $e->getMessage();
         $logger->write($message);
         return (ENVIRONMENT & DEVELOPMENT) > 0 ? $message : "";
     }
 }