Example #1
0
 /**
  * Perform a search on messages and get the results
  *
  * @param  string     $query The query string
  * @return \Message[] The results of the search
  */
 public function search($query)
 {
     Debug::startStopwatch('search.messages');
     $results = $this->mysqlSearch($query);
     Debug::finishStopwatch('search.messages');
     return $results;
 }
Example #2
0
 /**
  * Get a model from the database cache
  * @param  string $type    The type of the model (Player, Team etc.)
  * @param  int    $id      The database ID of the model
  * @param  mixed  $default What to return if the model doesn't exist in the cache
  * @return mixed  The Model if it exists in the cache, or $default if it
  *                        wasn't found
  */
 public function get($type, $id, $default = null)
 {
     if (!$this->has($type, $id)) {
         return $default;
     }
     Debug::logCacheFetch($type, $id);
     return $this->models[$type][$id];
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * @todo Error handling
  */
 public function trigger($channel, $message)
 {
     Debug::startStopwatch("notification.trigger.websocket");
     $port = \Service::getParameter('bzion.features.websocket.pull_port');
     $fp = @stream_socket_client("tcp://127.0.0.1:" . $port, $errno, $errstr, 1, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
     @fwrite($fp, json_encode(array('event' => array('type' => $channel, 'data' => $message))) . "\n");
     // Don't fclose() the connection because of a weird bug with React
     Debug::finishStopwatch("notification.trigger.websocket");
 }
Example #4
0
 /**
  * Perform a search on messages and get the results
  *
  * @param  string    $query The query string
  * @return Message[] The results of the search
  */
 public function search($query)
 {
     Debug::startStopwatch('search.messages');
     if (\Service::getParameter('bzion.features.elasticsearch.enabled')) {
         $results = $this->elasticSearch($query);
     } else {
         $results = $this->mysqlSearch($query);
     }
     Debug::finishStopwatch('search.messages');
     return $results;
 }
Example #5
0
 /**
  * Renders a view
  * @param  string $view       The view name
  * @param  array  $parameters An array of parameters to pass to the view
  * @return string The rendered view
  */
 protected function render($view, $parameters = array())
 {
     Debug::startStopwatch('view.render');
     $template = Service::getTemplateEngine();
     $ret = $template->render($view, $parameters);
     Debug::finishStopwatch('view.render');
     return $ret;
 }
Example #6
0
 /**
  * Sends a notification to some players
  *
  * @param mixed    $players A single player/ID or a player/ID list
  * @param string   $type   The type of the event
  * @param null|\Player|int $except A player who should not receive a notification
  * @param \Player $except
  */
 protected function doNotify($players, $type, $except = null)
 {
     Debug::log("Notifying about {$type}", array('players' => $players, 'except' => $except));
     if ($except instanceof \Player) {
         $except = $except->getId();
     }
     if (!is_array($players)) {
         $players = array($players);
     }
     foreach ($players as $player) {
         if ($player instanceof \Player) {
             $player = $player->getId();
         }
         if ($player != $except) {
             $notification = \Notification::newNotification($player, $type, $this);
             \Service::getContainer()->get('event_dispatcher')->dispatch(Events::NOTIFICATION_NEW, new NewNotificationEvent($notification));
         }
     }
 }
Example #7
0
 /**
  * Renders a view
  * @param  string $view       The view name
  * @param  array  $parameters An array of parameters to pass to the view
  * @return string The rendered view
  */
 protected function render($view, $parameters = array())
 {
     Debug::startStopwatch('view.render');
     $ret = $this->container->get('twig')->render($view, $parameters);
     Debug::finishStopwatch('view.render');
     return $ret;
 }