Exemplo n.º 1
0
 public static function create()
 {
     if (self::$instance === null) {
         self::$instance = new self();
         self::$instance->addLogger(new Sabel_Logger_File());
         register_shutdown_function(array(self::$instance, "output"));
     }
     return self::$instance;
 }
Exemplo n.º 2
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();
     $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 : "";
     }
 }
Exemplo n.º 3
0
function l($message, $level = SBL_LOG_INFO, $identifier = "default")
{
    Sabel_Logger::create()->write($message, $level, $identifier);
}