コード例 #1
1
ファイル: Database.php プロジェクト: kleitz/bzion
 /**
  * Create a new connection to the database
  *
  * @param string $host     The MySQL host
  * @param string $user     The MySQL user
  * @param string $password The MySQL password for the user
  * @param string $dbName   The MySQL database name
  *
  * @return Database A database object to interact with the database
  */
 public function __construct($host, $user, $password, $dbName)
 {
     if (Service::getContainer()) {
         if ($logger = Service::getContainer()->get('monolog.logger.mysql')) {
             $this->logger = $logger;
         }
     }
     $this->dbc = new mysqli($host, $user, $password, $dbName);
     if ($this->dbc->connect_errno) {
         $this->logger->addAlert($this->dbc->connect_error);
         throw new Exception($this->dbc->connect_error, $this->dbc->connect_errno);
     }
     $this->dbc->set_charset("utf8");
 }
コード例 #2
0
ファイル: AvatarModel.php プロジェクト: kleitz/bzion
 /**
  * Change the avatar of the object
  *
  * @param  string $avatar The file name of the avatar
  * @return self
  */
 public function setAvatar($avatar)
 {
     // Clear the thumbnail cache
     $imagine = Service::getContainer()->get('liip_imagine.cache.manager');
     $imagine->remove($avatar);
     return $this->updateProperty($this->avatar, 'avatar', $avatar, 's');
 }
コード例 #3
0
ファイル: AppKernel.php プロジェクト: kleitz/bzion
 public function boot()
 {
     parent::boot();
     if (!$this->container->getParameter('bzion.miscellaneous.development')) {
         if ($this->getEnvironment() != 'prod' || $this->isDebug()) {
             throw new ForbiddenDeveloperAccessException('You are not allowed to access this page in a non-production ' . 'environment. Please change the "development" configuration ' . 'value and clear the cache before proceeding.');
         }
     }
     if (in_array($this->getEnvironment(), array('profile', 'dev'), true)) {
         Debug::enable();
     }
     Service::setGenerator($this->container->get('router')->getGenerator());
     Service::setEnvironment($this->getEnvironment());
     Service::setModelCache(new ModelCache());
     Service::setContainer($this->container);
     $this->setUpTwig();
     // Ratchet doesn't support PHP's native session storage, so use our own
     // if we need it
     if (Service::getParameter('bzion.features.websocket.enabled') && $this->getEnvironment() !== 'test') {
         $storage = new NativeSessionStorage(array(), new DatabaseSessionHandler());
         $session = new Session($storage);
         Service::getContainer()->set('session', $session);
     }
     Notification::initializeAdapters();
 }
コード例 #4
0
ファイル: EventPusher.php プロジェクト: blast007/bzion
 /**
  * Create a new event pusher handler
  */
 public function __construct(LoopInterface $loop, OutputInterface $output = null)
 {
     $this->loop = $loop;
     $this->output = $output;
     $this->clients = new \SplObjectStorage();
     $this->subscriber = \Service::getContainer()->get('kernel.subscriber.bzion_subscriber');
     // Ping timer
     $loop->addPeriodicTimer(self::KEEP_ALIVE, array($this, 'ping'));
 }
コード例 #5
0
ファイル: Debug.php プロジェクト: blast007/bzion
 /**
  * Log a cache fetch in the data collector
  * @param string $type The type of the fetched model
  * @param int    $id   The ID of the fetched model
  */
 public static function logCacheFetch($type, $id)
 {
     if (\Service::isDebug() && \Service::getContainer()) {
         $collector = \Service::getContainer()->get('data_collector.bzion_database_collector', null);
         if ($collector) {
             $collector->logCacheFetch($type, $id);
         }
     }
 }
コード例 #6
0
ファイル: Database.php プロジェクト: allejo/bzion
 /**
  * Create a new connection to the database
  *
  * @param string $host     The MySQL host
  * @param string $user     The MySQL user
  * @param string $password The MySQL password for the user
  * @param string $dbName   The MySQL database name
  */
 public function __construct($host, $user, $password, $dbName)
 {
     if (Service::getContainer()) {
         if ($logger = Service::getContainer()->get('monolog.logger.mysql')) {
             $this->logger = $logger;
         }
     }
     try {
         // TODO: Persist
         $this->dbc = new PDO('mysql:host=' . $host . ';dbname=' . $dbName . ';charset=utf8', $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false));
     } catch (PDOException $e) {
         $this->logger->addAlert($e->getMessage());
         throw new Exception($e->getMessage(), $e->getCode());
     }
 }
コード例 #7
0
ファイル: MessageSearch.php プロジェクト: kleitz/bzion
 /**
  * Perform a search on messages using Elasticsearch
  *
  * @param  string    $query The query string
  * @return Message[] The results of the search
  */
 private function elasticSearch($query)
 {
     $finder = \Service::getContainer()->get('fos_elastica.finder.search');
     $boolQuery = new Bool();
     // We have only stored "active" messages and groups on Elasticsearch's
     // database, so there is no check for that again
     if ($this->player) {
         // Make sure that the parent of the message (i.e. the group that the
         // message belongs into) has the current player as its member
         $recipientQuery = new Term();
         $recipientQuery->setTerm('members', $this->player->getId());
         $parentQuery = new HasParent($recipientQuery, 'group');
         $boolQuery->addMust($parentQuery);
     }
     $fieldQuery = new Match();
     $fieldQuery->setFieldQuery('content', $query)->setFieldFuzziness('content', 'auto');
     $boolQuery->addMust($fieldQuery);
     return $finder->find($boolQuery);
 }
コード例 #8
0
ファイル: AvatarModel.php プロジェクト: blast007/bzion
 /**
  * Change the avatar of the object
  *
  * @param  string $avatar The file name of the avatar
  * @return self
  */
 public function setAvatar($avatar)
 {
     if (!empty($this->avatar) && $avatar != $this->avatar) {
         // Remove the old avatar
         unlink(DOC_ROOT . $this->avatar);
     }
     // Clear the thumbnail cache
     $imagine = Service::getContainer()->get('liip_imagine.cache.manager');
     $imagine->remove($this->avatar);
     return $this->updateProperty($this->avatar, 'avatar', $avatar, 's');
 }
コード例 #9
0
ファイル: Controller.php プロジェクト: bchhun/bzion
 /**
  * Gets the monolog logger
  *
  * @param  string         $channel The log channel, defaults to the Controller's default
  * @return Monolog\Logger
  */
 protected static function getLogger($channel = null)
 {
     if (!$channel) {
         $channel = static::getLogChannel();
     }
     return Service::getContainer()->get("monolog.logger.{$channel}");
 }
コード例 #10
0
ファイル: Event.php プロジェクト: allejo/bzion
 /**
  * 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));
         }
     }
 }
コード例 #11
0
ファイル: DatabaseQuery.php プロジェクト: kleitz/bzion
 /**
  * Mark a query as finished
  *
  * @param  mixed $return The returned values of the query
  * @return void
  */
 public function finish(&$return)
 {
     $duration = Debug::finishStopwatch($this->eventName);
     Debug::log("Database {$this->queryType} query", array("query" => $this->query, "params" => $this->params, "duration" => "{$duration} ms"), 'mysql');
     if (\Service::isDebug()) {
         $this->finishTime = microtime(true);
         $this->duration = ($this->finishTime - $this->startTime) * self::MICROSECONDS_IN_SECOND;
         $this->results = $return;
         $collector = \Service::getContainer()->get('data_collector.bzion_database_collector', null);
         if ($collector) {
             $collector->logQuery($this);
         }
     }
 }
コード例 #12
0
ファイル: ServiceTest.php プロジェクト: Chris7/JoliCi
 /**
  * @param Service $serviceMock
  * @depends testConstructInitialisesAllTheFields
  */
 public function testSetAndGetContainer($serviceMock)
 {
     $dockerContainerMock = $this->getMockBuilder('Docker\\Container')->setMethods(null)->getMock();
     $serviceMock->setContainer($dockerContainerMock);
     $this->assertSame($dockerContainerMock, $serviceMock->getContainer());
 }
コード例 #13
0
ファイル: Server.php プロジェクト: allejo/bzion
 /**
  * Update the server with current bzfquery information
  * return self
  */
 public function forceUpdate()
 {
     $this->info = bzfquery($this->getAddress());
     $this->updated = TimeDate::now();
     $this->online = !isset($this->info['error']);
     $this->db->execute("UPDATE servers SET info = ?, online = ?, updated = UTC_TIMESTAMP() WHERE id = ?", array(serialize($this->info), $this->online, $this->id));
     // If a server is offline, log it
     if (!$this->online) {
         if ($logger = \Service::getContainer()->get('logger')) {
             $id = $this->getId();
             $address = $this->getAddress();
             $reason = $this->info['error'];
             $logger->notice("Connection to server #{$id} ({$address}) failed: {$reason}");
         }
     }
     return $this;
 }