public function message_put(array $data)
 {
     // 1. Store the message
     /**
      * @var \WMD\Models\Message
      */
     $msg = \WMD\Models\Message::create($data);
     $ok = $msg->save();
     if (!$ok) {
         throw new \Exception('Failed to add message');
     }
     // 2. Dispatch the message to registred modules
     foreach ($this->dispatchers as $modName => $module) {
         Log::debug(__METHOD__ . ' Dispatch test srvName:"' . $msg->srv_name . '", modName:"' . $modName . '"');
         list($ok, $mod_params) = $this->router->is_module_dispatch($msg->srv_name, $modName, $msg->to, $msg->from);
         if ($ok === true) {
             Log::debug(__METHOD__ . ' ... Dispatching to:"' . $msg->to . '", from:"' . $msg->from . '", params:"' . $mod_params . '"');
             $module->message_put($msg->proxy_at, $msg->from, $msg->body, $msg->srv_addr, $msg->srv_at, $mod_params);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Trap some Model events
  * @see http://laravel.com/docs/5.1/eloquent#events
  */
 protected static function boot()
 {
     parent::boot();
     // Model event : creating
     Message::creating(function ($msg) {
         // "SMS" datetime are big timestamp,
         // divide by 1000 then format as DataTime
         if (is_numeric($msg->proxy_at)) {
             if ($msg->proxy_at > 9999999999) {
                 $msg->proxy_at /= 1000;
             }
             $msg->proxy_at = Carbon::createFromTimeStamp($msg->proxy_at);
         }
         if (is_numeric($msg->srv_at)) {
             if ($msg->srv_at > 9999999999) {
                 $msg->srv_at /= 1000;
             }
             $msg->srv_at = Carbon::createFromTimeStamp($msg->srv_at);
         }
     });
 }