本文整理汇总了PHP中Service::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Service::getContainer方法的具体用法?PHP Service::getContainer怎么用?PHP Service::getContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service::getContainer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 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: setAvatar
/**
* 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: boot
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: __construct
/**
* 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: logCacheFetch
/**
* 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: __construct
/**
* 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: elasticSearch
/**
* 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: setAvatar
/**
* 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: getLogger
/**
* 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: doNotify
/**
* 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: finish
/**
* 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: testSetAndGetContainer
/**
* @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: forceUpdate
/**
* 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;
}