protected function renderTemplate($template_path = 'index/index.html.twig', array $context = array()) { /** @var \Twig_Loader_Filesystem $environment */ $environment = getContainer()->get('zero.twig.filesystem_loader'); $global_template_path = null; $namespace_template_path = null; if (strpos($template_path, '@') === 0) { $global_template_path = substr($template_path, 1); $namespace_template_path = $template_path; } else { $global_template_path = $template_path; } /** @var \Twig_Environment $engine */ $engine = getContainer()->get('zero.twig.engine'); try { $template = $engine->loadTemplate($global_template_path); $response = $template->render($context); return new Response($response); } catch (\Exception $e) { if ($namespace_template_path) { $namespace = substr($template_path, 1, strpos($template_path, '/') - 1); $custom_template_dir = $this->addTemplateRoot(); if ($custom_template_dir) { $environment->addPath($custom_template_dir, $namespace); } $template = $engine->loadTemplate($namespace_template_path); $response = $template->render($context); return new Response($response); } else { throw new \Exception('Twig模板文件格式错误: ' . $template_path); } } }
protected function execute(InputInterface $input, OutputInterface $output) { // Use all the memory ini_set('memory_limit', '-1'); gc_enable(); error_reporting(1); error_reporting(E_ALL); define('DISCORDPHP_STARTTIME', microtime(true)); define('BASEDIR', __DIR__); define('SOVEREIGN_CONFIG_FILE', realpath('./' . ltrim($input->getOption('configFile'), '/'))); // Init the container object $container = getContainer(); // Load the bot into the service container $container->share('app', Sovereign::class)->withArgument($container); try { // Init the bot $container->get('log')->addInfo('Sovereign is starting up..'); $bot = $container->get('app'); // Register the default plugins and services, and boot them. $container->addServiceProvider(SystemPluginServiceProvider::class); } catch (\Exception $e) { $container->get('log')->addError('An error occurred: ' . $e->getMessage()); die; } // Launch the bot $bot->run(); }
/** * This is for the pthreads compatibility - for some reason the DB just goes t**s up when using pthreads * and PDO.. Hence the __wakeup() call, that restarts the database. * No numbers on it, but it more than likely adds quite a bit of latency. */ public function __wakeup() { $this->container = getContainer(); $this->log = $this->container->get('log'); $this->config = $this->container->get('config'); $this->pdo = $this->connect(); }
function doBootstrap() { $container = getContainer(); // bootstrap PSX\Bootstrap::setupEnvironment($container->get('config')); // check whether http server is available $server = false; try { $config = $container->get('config'); $http = $container->get('http'); $request = new PSX\Http\GetRequest($config['psx_url'] . '/'); $response = $http->request($request); $body = $response->getBody(); if ($response->getCode() == 200 && !empty($body) && strpos($body, 'http-equiv="X-XRDS-Location"') !== false) { echo 'Found webserver and amun instance at ' . $config['psx_url'] . "\n"; $server = true; } else { echo 'Webserver not running or amun instance not available at ' . $config['psx_url'] . "\n"; echo $body . "\n"; } } catch (\Exception $e) { echo 'Webserver not running: ' . $e->getMessage() . "\n"; } define('HTTP_SERVER', $server); }
protected function setUp() { parent::setUp(); $container = getContainer(); self::$databaseDumper = $container->get('dumper.database.mysql'); self::$shellExecutor = $container->get('helper.shell_executor'); }
public static function getTypes() { /** @var \Zero\Component\Kernel\Container $container */ $container = getContainer(); $structure_types = $container->getParameter('structure_type'); return $structure_types; }
public function getUserInfo($user_id) { /** @var \Tachigo\User\Aware\Component\UserAwareDispatcher $dispatcher */ $dispatcher = getContainer()->tag('tachigo_user_dispatcher'); /** @var \Tachigo\User\Aware\Hook\UserHook $hook */ $hook = getContainer()->tag('tachigo_user_hook.user'); $hook->setUserId($user_id); $dispatcher->fire($hook); return $hook->getResults(); }
public function testGet() { $url = new Url($this->getEndpoint() . '?format=xml'); $response = $this->signedRequest('GET', $url); $this->assertEquals(200, $response->getCode()); $xml = simplexml_load_string($response->getBody()); // check subject $this->assertEquals(true, isset($xml->name)); $this->assertEquals(getContainer()->get('user')->getName(), (string) $xml->name); }
protected function assertResultSetResponse(Response $response) { $this->assertEquals(200, $response->getCode(), $response->getBody()); $result = Json::decode($response->getBody()); $this->assertEquals(true, isset($result['totalResults']), $response->getBody()); $this->assertEquals(true, isset($result['startIndex']), $response->getBody()); $this->assertEquals(true, isset($result['itemsPerPage']), $response->getBody()); $tblActivity = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Activity')->getName(); $tblAccount = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Account')->getName(); $count = $this->sql->getField('SELECT COUNT(*) FROM ' . $tblActivity . ' INNER JOIN ' . $tblAccount . ' ON ' . $tblActivity . '.userId = ' . $tblAccount . '.id'); $this->assertEquals($count, $result['totalResults']); }
public function testGet() { $url = new Url($this->getEndpoint()); $response = $this->signedRequest('GET', $url); $this->assertEquals(200, $response->getCode()); $dom = new DOMDocument(); $dom->loadXML($response->getBody()); $persons = $dom->getElementsByTagNameNS('http://xmlns.com/foaf/0.1/', 'Person'); $person = $persons->item(0); $this->assertEquals(true, $person instanceof DOMElement); $this->assertEquals(getContainer()->get('user')->getName(), $person->getElementsByTagName('name')->item(0)->nodeValue); }
public function testPut() { $rightIds = array(1, 2, 3, 4); $record = $this->getHandler()->getRecord(); $record->setId(1); $record->setTitle('foobar'); $record->rights = implode(',', $rightIds); $this->assertPositiveResponse($this->put($record)); $actual = $this->table->getRow(array('id', 'title'), new Condition(array('id', '=', 1))); unset($record->rights); $expect = array_map('strval', $record->getData()); $table = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Group\\Right'); $this->assertEquals($expect, $actual); $this->assertEquals($rightIds, $table->getCol('rightId', new Condition(array('groupId', '=', 1)))); }
protected function setUp() { // check whether webserver is started if (!HTTP_SERVER) { $this->markTestSkipped('Webserver not available'); } // call parent parent::setUp(); // get api credentials $this->config = getContainer()->get('config'); $this->sql = getContainer()->get('sql'); $this->registry = getContainer()->get('registry'); $this->user = getContainer()->get('user'); $this->http = new Http(); $this->oauth = new Oauth($this->http); if (!$this->user->isAnonymous()) { // check whether we have API credentials get API credentials $api = $this->sql->getRow('SELECT id, consumerKey, consumerSecret FROM `amun_oauth` ORDER BY id ASC LIMIT 1'); $status = \AmunService\Oauth\Record::ACCESS; if (!empty($api)) { $this->consumerKey = $api['consumerKey']; $this->consumerSecret = $api['consumerSecret']; $sql = <<<SQL SELECT \t`token`, \t`tokenSecret` FROM \t`amun_oauth_request` WHERE \t`apiId` = {$api['id']} AND \t`userId` = {$this->user->getId()} AND \t`status` = {$status} LIMIT 1 SQL; $request = $this->sql->getRow($sql); if (!empty($request)) { $this->token = $request['token']; $this->tokenSecret = $request['tokenSecret']; } else { $this->markTestSkipped('No oauth request available'); } } else { $this->markTestSkipped('We have no oauth application'); } } }
function detallesContenedor() { if (validarUsuarioAdministrador()) { require_once 'modulos/cdn/modelos/cdnModelo.php'; $containerName = $_GET['i']; if (isset($containerName)) { $container = getContainer($containerName); $objects = $container->get_objects(); require_once 'modulos/administracion/vistas/detallesContenedorArchivos.php'; } else { setSessionMessage("No se especificó el nombre del contenedor"); redirect("administracion/archivos"); } } else { goToIndex(); } }
protected function handle() { $session = $this->getSession(); try { $user_info = $this->checkSessionAuth($session, $this->sessionAuthKey); $session->addFlash('success', '欢迎回来, ' . $user_info['username']); return new RedirectResponse($this->generateUrl('admin_homepage')); } catch (\Exception $e) { $request = $this->getRequest(); $administrators = $this->getContainer()->getParameter('administrators'); if ($administrators) { $administrators = $administrators->toArray(); } else { $administrators = array(); } if ($request->getMethod() == 'POST') { $username = $request->request->get('username', ''); $password = $request->request->get('password', ''); if (!isset($administrators[$username])) { $session->addFlash('error', '用户名不存在'); return new RedirectResponse($this->generateUrl('admin_login')); } elseif ($administrators[$username]['password'] != md5($password)) { $session->addFlash('error', '密码错误'); return new RedirectResponse($this->generateUrl('admin_login')); } else { $this->rememberSession($session, $this->sessionAuthKey, $administrators[$username]); $session->addFlash('success', '欢迎回来, ' . $username); return new RedirectResponse($this->generateUrl('admin_homepage')); } } } $login_template_id = getContainer()->getParameter('metronic_theme.login_id'); if (!$login_template_id) { $login_template_id = 1; } return $this->render('_passport/login_' . $login_template_id . '.html.twig'); }
public function testVideoRequest() { $testCase = $this; $http = new Http(new Callback(function ($request) use($testCase) { $response = <<<TEXT HTTP/1.1 200 OK Date: Thu, 26 Sep 2013 16:36:26 GMT Content-Type: application/json; charset=UTF-8 { "type":"video", "version":"1.0", "title":"Beethoven - Rondo 'Die wut ueber den verlorenen groschen'", "author_name":"LukasSchuch", "author_url":"http:\\/\\/www.youtube.com\\/user\\/LukasSchuch", "provider_name":"YouTube", "provider_url":"http:\\/\\/www.youtube.com\\/", "thumbnail_url":"http:\\/\\/i2.ytimg.com\\/vi\\/AKjzEG1eItY\\/hqdefault.jpg", "thumbnail_width":480, "thumbnail_height":360, "html":"<iframe width=\\"459\\" height=\\"344\\" src=\\"http:\\/\\/www.youtube.com\\/embed\\/AKjzEG1eItY?fs=1&feature=oembed\\" frameborder=\\"0\\" allowfullscreen><\\/iframe>", "width":240, "height":160 } TEXT; return Response::convert($response, ResponseParser::MODE_LOOSE)->toString(); })); $oembed = new Oembed($http, getContainer()->get('importer')); $url = new Url('http://127.0.0.1/oembed/video?url=http%3A%2F%2Flocalhost.com%2Fresource'); $type = $oembed->request($url); $this->assertInstanceof('PSX\\Oembed\\Type\\Video', $type); $this->assertEquals('video', $type->getType()); $this->assertEquals('1.0', $type->getVersion()); $this->assertEquals('Beethoven - Rondo \'Die wut ueber den verlorenen groschen\'', $type->getTitle()); $this->assertEquals('LukasSchuch', $type->getAuthorName()); $this->assertEquals('http://www.youtube.com/user/LukasSchuch', $type->getAuthorUrl()); $this->assertEquals('YouTube', $type->getProviderName()); $this->assertEquals('http://www.youtube.com/', $type->getProviderUrl()); $this->assertEquals('http://i2.ytimg.com/vi/AKjzEG1eItY/hqdefault.jpg', $type->getThumbnailUrl()); $this->assertEquals('480', $type->getThumbnailWidth()); $this->assertEquals('360', $type->getThumbnailHeight()); $this->assertEquals('<iframe width="459" height="344" src="http://www.youtube.com/embed/AKjzEG1eItY?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>', $type->getHtml()); $this->assertEquals('240', $type->getWidth()); $this->assertEquals('160', $type->getHeight()); }
require_once 'lib/nangkoelib.php'; $lokasibpjs = checkPostGet('lokasibpjs', ''); $jenisbpjs = checkPostGet('jenisbpjs', ''); $bebankaryawan = checkPostGet('bebankaryawan', '0'); $bebanperusahaan = checkPostGet('bebanperusahaan', '0'); $maxgaji = checkPostGet('maxgaji', '0'); $method = checkPostGet('method', ''); switch ($method) { case 'loaddata': getContainer(); break; case 'update': $str = "update " . $dbname . ".sdm_5bpjs set bebankaryawan='" . $bebankaryawan . "', bebanperusahaan='" . $bebanperusahaan . "', maxgaji='" . $maxgaji . "' where lokasibpjs='" . $lokasibpjs . "' and jenisbpjs='" . $jenisbpjs . "'"; // print_r($str); if (mysql_query($str)) { getContainer(); } else { echo "DB Error : " . mysql_error($conn); } break; default: break; } function getContainer() { global $conn; global $dbname; $str = "select * from " . $dbname . ".sdm_5bpjs"; $qry = mysql_query($str) or die(mysql_error()); while ($res = mysql_fetch_object($qry)) { $no += 1;
<?php $loader = (require 'vendor/autoload.php'); $loader->add('PSX', 'tests'); $container = getContainer(); PSX\Bootstrap::setupEnvironment($container->get('config')); function getContainer() { static $container; if ($container === null) { $container = new PSX\Dependency\DefaultContainer(); $container->setParameter('config.file', array('psx_url' => 'http://127.0.0.1/projects/psx/public', 'psx_dispatch' => 'index.php/', 'psx_timezone' => 'UTC', 'psx_debug' => true, 'psx_path_cache' => sys_get_temp_dir(), 'psx_path_library' => __DIR__ . '/../src')); } return $container; }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\User\\Friend'); }
public function getConnection() { return $this->createDefaultDBConnection(getContainer()->get('sql'), getContainer()->get('config')->get('psx_sql_db')); }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\Oauth\\Request'); }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\Content\\Page\\Gadget'); }
protected function getHandler($table) { return getContainer()->get('handlerManager')->getHandler($table); }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\Core\\Service'); }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\User\\Group\\Right'); }
public function getHandler() { return getContainer()->get('handlerManager')->getHandler('AmunService\\Openid\\Access'); }
/** * @return \Zero\Component\Kernel\Container */ public static function getContainer() { return getContainer(); }
public function setUp() { parent::setUp(); require_once getcwd() . '/Container.php'; $this->container = getContainer(); }
/** * @return \TknyMed\ForumModule\Database\MySQL\ForumDatabase */ public static function getDb() { return getContainer()->tag('forum_db'); }
/** * @return \TknyMed\PortalModule\Database\MySQL\PortalDatabase */ public static function getDb() { return getContainer()->tag('portal_db'); }