本文整理汇总了PHP中Symfony\Component\HttpKernel\KernelInterface::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP KernelInterface::getContainer方法的具体用法?PHP KernelInterface::getContainer怎么用?PHP KernelInterface::getContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\KernelInterface
的用法示例。
在下文中一共展示了KernelInterface::getContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrlFromPath
/**
* Generates a url from a given patch
*
* @param $path
* @param $method
* @return string
*/
protected function getUrlFromPath($path, $method = 'GET')
{
try {
$baseUrl = $this->kernel->getContainer()->getParameter('router.request_context.base_url');
} catch (InvalidArgumentException $e) {
$baseUrl = '';
}
try {
$host = $this->kernel->getContainer()->getParameter('router.request_context.host');
} catch (InvalidArgumentException $e) {
$host = 'localhost';
}
$requestContext = new RequestContext($baseUrl, $method, $host);
$router = $this->getRouter();
$router->setContext($requestContext);
$urlStack = parse_url($path);
$info = $router->match($urlStack['path']);
$route = $info['_route'];
unset($info['_route']);
$url = $this->getUrl($route, $info);
if (isset($urlStack['query'])) {
$url .= '?' . $urlStack['query'];
}
return $url;
}
示例2: testServiceIsGettable
/**
* Checks if the app can get the service from the container
*/
public function testServiceIsGettable()
{
$serviceCallableName = 'open_exchange_rates_service';
$this->assertTrue(static::$kernel->getContainer()->has($serviceCallableName));
static::$kernel->getContainer()->get($serviceCallableName);
$this->assertTrue(true);
}
示例3: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$routes = $this->router->getRouteCollection();
$route = $routes->get($request->attributes->get('_route'));
if (!$route->getOption('requires_license')) {
return;
}
if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
// Checking for whitelisted users
try {
$user = $this->tokenStorage->getToken()->getUser();
$today = date('Y-m-d');
if ($user instanceof UserInterface) {
$whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
foreach ($whitelist as $allowed) {
if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
return;
}
}
}
} catch (\Exception $e) {
// Do nothing
}
$url = $this->router->generate('atlassian_connect_unlicensed');
$response = new RedirectResponse($url);
$event->setResponse($response);
}
}
示例4: theSystemShouldHaveTheFollowingInternetProfiles
/**
* @Given the system should have the following internet profiles:
*
* @param PyStringNode $body
*
*/
public function theSystemShouldHaveTheFollowingInternetProfiles(PyStringNode $body)
{
/** @var CollectProfilesTestWorker $collectProfilesTestWorker */
$collectProfilesTestWorker = $this->kernel->getContainer()->get('muchacuba.internet.collect_profiles_test_worker');
Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectProfilesTestWorker->collect()), (array) json_decode($body->getRaw(), true)));
$this->rootContext->ignoreState('Muchacuba\\Internet\\Profile');
}
示例5: theSystemShouldHaveTheFollowingDebtOperations
/**
* @Given the system should have the following recharge card profiles debt operations
*/
public function theSystemShouldHaveTheFollowingDebtOperations(PyStringNode $body)
{
/** @var CollectOperationsTestWorker $collectOperationsTestWorker */
$collectOperationsTestWorker = $this->kernel->getContainer()->get('muchacuba.recharge_card.profile.debt.collect_operations_test_worker');
Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectOperationsTestWorker->collect()), (array) json_decode($body->getRaw(), true)));
$this->rootContext->ignoreState('Muchacuba\\RechargeCard\\Profile\\Debt\\Operation');
}
示例6: build
/**
* @param \Jarves\Configuration\Object[] $objects
* @param OutputInterface $output
*
* @param bool $overwrite
* @throws ModelBuildException
*/
public function build(array $objects, OutputInterface $output, $overwrite = false)
{
/** @var $jarves \Jarves\Jarves */
$jarves = $this->kernel->getContainer()->get('jarves');
$output->writeln('Propel Build');
foreach ($objects as $object) {
if ($this->kernel->getContainer()->get($object->getStorageService()) instanceof \Jarves\Storage\Propel) {
$output->write('Build object ' . $object->getId() . ' => ' . $object->getTable() . ' ... ');
$bundlePath = $jarves->getBundleDir($object->getBundle()->getName());
$modelsFile = sprintf('%sResources/config/schema/%s.schema.xml', $bundlePath, strtolower($object->getTable()));
if (!$overwrite && file_exists($modelsFile) && file_get_contents($modelsFile)) {
$xml = @simplexml_load_file($modelsFile);
if (false === $xml) {
$errors = libxml_get_errors();
throw new ModelBuildException(sprintf('Parse error in %s: %s', $modelsFile, json_encode($errors, JSON_PRETTY_PRINT)));
}
} else {
$xml = simplexml_load_string('<database></database>');
}
$xml['namespace'] = $object->getBundle()->getNamespace() . '\\Model';
// $xml['package'] = $object->getBundle()->getNamespace() . '\\Model';
$xml['name'] = 'default';
$this->declareTable($xml, $object);
if (!is_dir(dirname($modelsFile))) {
mkdir(dirname($modelsFile), 0777, true);
}
file_put_contents($modelsFile, $this->getFormattedXml($xml));
$output->writeln($modelsFile . ' written.');
unset($xml);
}
}
}
示例7: setUp
public function setUp()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->dm = static::$kernel->getContainer()->get('doctrine.odm.mongodb.document_manager');
parent::setUp();
}
示例8: iMustHaveTicketForAllEvents
/**
* @Then /^у меня должна быть подписка на все активные ивенты$/
*/
public function iMustHaveTicketForAllEvents()
{
$activeEvents = $this->kernel->getContainer()->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Event')->findBy(array('active' => true));
$user = $this->kernel->getContainer()->get('fos_user.user_manager')->findUserByEmail('test@fwdays.com');
$tickets = $this->kernel->getContainer()->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->findBy(array('user' => $user->getId()));
assertEquals(count($tickets), count($activeEvents));
}
示例9: getFallBackTheme
/**
* @return string|null
*/
protected function getFallBackTheme()
{
if (null !== $this->kernel->getContainer()) {
return $this->kernel->getContainer()->getParameter('fallback_theme');
}
return null;
}
示例10: theSystemShouldHaveTheFollowingOperations
/**
* @Then the system should have the following info sms subscription low balance reminder logs:
*
* @param PyStringNode $body
*/
public function theSystemShouldHaveTheFollowingOperations(PyStringNode $body)
{
/** @var CollectLogsTestWorker $collectLogsTestWorker */
$collectLogsTestWorker = $this->kernel->getContainer()->get('muchacuba.info_sms.subscription.low_balance_reminder.collect_logs_test_worker');
Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectLogsTestWorker->collect()), (array) json_decode($body->getRaw(), true)));
$this->rootContext->ignoreState('Muchacuba\\InfoSms\\Subscription\\LowBalanceReminder\\Log');
}
示例11: theSystemShouldHaveTheFollowingUniquenesses
/**
* @Given the system should have the following uniquenesses:
*/
public function theSystemShouldHaveTheFollowingUniquenesses(PyStringNode $body)
{
/** @var CollectUniquenessTestWorker $collectUniquenessTestWorker */
$collectUniquenessTestWorker = $this->kernel->getContainer()->get('cubalider.unique.collect_uniqueness_test_worker');
Assert::assertTrue((new SimpleFactory())->createMatcher()->match(iterator_to_array($collectUniquenessTestWorker->collect()), (array) json_decode($body->getRaw(), true)));
$this->rootContext->ignoreState('Cubalider\\Uniqueness');
}
示例12: init
/**
* @BeforeScenario
*/
public function init($event)
{
$this->translationsApi = $this->kernel->getContainer()->get('jlaso_translations.client.api');
$apiConfig = $this->kernel->getContainer()->getParameter('jlaso_translations_api_access');
$this->project_id = 1;
// cuando se crea de cero siempre es el uno - $apiConfig['project_id'];
$this->em = $this->kernel->getContainer()->get('doctrine.orm.default_entity_manager');
}
示例13: getContainer
/**
* @return ContainerInterface
*/
protected function getContainer()
{
if ($this->kernel === NULL) {
$this->kernel = $this->createKernel();
$this->kernel->boot();
}
return $this->kernel->getContainer();
}
示例14: initKernel
private static function initKernel()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
static::$container = static::$kernel->getContainer();
static::$doctrine = static::$container->get('doctrine');
static::$om = static::$doctrine->getManager();
}
示例15: buildClient
/**
* Build client
*
* @return $this Self object
*/
public function buildClient()
{
$this->kernel = new \AppKernel('test', false);
$this->kernel->boot();
$this->session->clear();
$this->client = $this->kernel->getContainer()->get('test.client');
$this->environmentBuilder->setUp($this->kernel);
}