コード例 #1
0
ファイル: Server.php プロジェクト: monkeylady/wechat
 /**
  * 魔术调用
  *
  * @param string $method
  * @param array  $args
  *
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (in_array($method, $this->events, true)) {
         $callback = array_shift($args);
         is_callable($callback) && $this->listeners->set($method, $callback);
         return;
     }
 }
コード例 #2
0
ファイル: Wechat.php プロジェクト: xutongtong/wechat
 /**
  * 监听
  *
  * @param string          $target
  * @param string|callable $type
  * @param callable        $callback
  *
  * @return Wechat
  */
 public function on($target, $type, $callback = null)
 {
     if (is_null($callback)) {
         $callback = $type;
         $type = '*';
     }
     if (!is_callable($callback)) {
         throw new Exception("{$callback} 不是一个可调用的函数或方法");
     }
     $listeners = $this->listeners->get("{$target}.{$type}") ?: array();
     array_push($listeners, $callback);
     $this->listeners->set("{$target}.{$type}", $listeners);
     return $this;
 }