本文整理汇总了PHP中getContainer函数的典型用法代码示例。如果您正苦于以下问题:PHP getContainer函数的具体用法?PHP getContainer怎么用?PHP getContainer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getContainer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderTemplate
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);
}
}
}
示例2: execute
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();
}
示例3: __wakeup
/**
* This is for the pthreads compatibility - for some reason the DB just goes tits 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();
}
示例4: doBootstrap
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);
}
示例5: setUp
protected function setUp()
{
parent::setUp();
$container = getContainer();
self::$databaseDumper = $container->get('dumper.database.mysql');
self::$shellExecutor = $container->get('helper.shell_executor');
}
示例6: getTypes
public static function getTypes()
{
/** @var \Zero\Component\Kernel\Container $container */
$container = getContainer();
$structure_types = $container->getParameter('structure_type');
return $structure_types;
}
示例7: getUserInfo
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();
}
示例8: testGet
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);
}
示例9: assertResultSetResponse
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']);
}
示例10: testGet
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);
}
示例11: testPut
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))));
}
示例12: setUp
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');
}
}
}
示例13: detallesContenedor
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();
}
}
示例14: handle
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');
}
示例15: testVideoRequest
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());
}