function getToken() { $cache = DI::get()->getCache(); if (isset($_GET['token'])) { $token = urldecode($_GET['token']); } elseif (!$cache->has('audioToken')) { $response = curl('http://api.pleer.com/token.php', ['grant_type' => 'client_credentials'], true); if (!($token = $response['access_token'])) { die('Abnormal API behavior: unable to receive access token'); } $ttl = isset($response['expires_in']) ? $response['expires_in'] : 3600; $cache->set('audioToken', $token, $ttl); } else { $token = $cache->get('audioToken'); } return $token; }
public function testInvite() { $user1 = $this->getMockUser(); $user2 = $this->getMockUser(); DI::get()->container()->add('eventloop', MockEventLoop::class, true); $dummy = function () { }; // send invitation $inviteTimestamp = time(); list($user1id, $time) = $this->privates->invite($user1, $user2, $dummy); $this->assertEquals($user1->getId(), $user1id); $this->assertNull($time); // repeat sending invitation, but it should return sign of 'already sent' by timestamp of first attempt list($user1id, $time) = $this->privates->invite($user1, $user2, $dummy); $this->assertEquals($user1->getId(), $user1id); $this->assertEquals($inviteTimestamp, $time); // accept invitation list($user1id, $time) = $this->privates->invite($user2, $user1, $dummy); $this->assertNull($user1id); $this->assertNull($time); }
<?php use Core\DI; use Core\DIBuilder; $DS = DIRECTORY_SEPARATOR; define('ROOT', __DIR__); function basicSetup() { error_reporting(E_ALL | E_STRICT); date_default_timezone_set('Europe/Moscow'); setlocale(LC_CTYPE, "en_US.UTF8"); setlocale(LC_TIME, "en_US.UTF8"); $defaultEncoding = 'UTF-8'; mb_internal_encoding($defaultEncoding); mb_regex_encoding($defaultEncoding); } if (!isset($loader)) { $loader = (require_once ROOT . $DS . 'vendor' . $DS . 'autoload.php'); $loader->register(); } basicSetup(); $container = DI::get()->container(); DIBuilder::setupNormal($container);
<?php \Core\DI::bind("App\\Models\\Game\\GameModelInterface", function () { $db = \Core\DB::getInstance(); return new \App\Models\Game\GameModel(new \App\Domain\Logic\GameLogic(new \App\Domain\Factories\ShipFactory()), new \App\Domain\Repository\Game\GameRepository(new App\Persistence\Database\GamePersistence($db), new App\Persistence\Database\ShotPersistence($db)), \Core\Session::getInstance()); });
/** * @param $routeAction * @param null $args * @return mixed * @throws \Exception */ protected function callControllerFunction($routeAction, $args = null) { list($controller, $function) = explode('@', $routeAction); $instance = DI::getInstanceOf($controller); if (!empty($args)) { return call_user_func_array(array($instance, $function), $args); } return $instance->{$function}(); }
public function __wakeup() { $this->db = DI::get()->container()->get('db'); }
private function logQuery($sql, array $params) { if ($this->isLogQueries) { /** @var $logger Logger */ $logger = DI::get()->getLogger(); $logger->info('SQL: ' . $sql, $params); } }