本文整理汇总了PHP中Symfony\Component\HttpKernel\KernelInterface::getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:PHP KernelInterface::getEnvironment方法的具体用法?PHP KernelInterface::getEnvironment怎么用?PHP KernelInterface::getEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\KernelInterface
的用法示例。
在下文中一共展示了KernelInterface::getEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if ('test' === $this->kernel->getEnvironment()) {
$definition = $container->getDefinition('translator.default');
$definition->setClass('Braincrafted\\Bundle\\TestingBundle\\Translator\\NoTranslator');
}
}
示例3: __construct
/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
*/
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
parent::__construct('Symfony', Kernel::VERSION . ' - ' . $kernel->getName() . '/' . $kernel->getEnvironment() . ($kernel->isDebug() ? '/debug' : ''));
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
}
示例4: onConsoleTerminate
/**
* @param ConsoleTerminateEvent $event
*/
public function onConsoleTerminate(ConsoleTerminateEvent $event)
{
$command = $event->getCommand();
$environment = $this->kernel->getEnvironment();
if ($environment == 'test' && $command instanceof LoadMigrationsCommand && $event->getInput()->getOption('force')) {
$executor = new CommandExecutor($environment, $event->getOutput(), $command->getApplication());
$executor->runCommand('oro:test:schema:update', ['--process-isolation' => true]);
}
}
示例5: getCoreBundlesClasses
/**
* @return array
*/
protected function getCoreBundlesClasses()
{
$bundles = [\Symfony\Bundle\FrameworkBundle\FrameworkBundle::class, \Symfony\Bundle\SecurityBundle\SecurityBundle::class, \Symfony\Bundle\TwigBundle\TwigBundle::class, \Symfony\Bundle\MonologBundle\MonologBundle::class, \Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class, \Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class, \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class, \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class, \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class, \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class, \FOS\JsRoutingBundle\FOSJsRoutingBundle::class, \Bazinga\Bundle\JsTranslationBundle\BazingaJsTranslationBundle::class, \Liip\ImagineBundle\LiipImagineBundle::class, \Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle::class, \Cache\AdapterBundle\CacheAdapterBundle::class, \WellCommerce\Bundle\AppBundle\WellCommerceAppBundle::class];
if (in_array($this->kernel->getEnvironment(), ['dev', 'test'])) {
$bundles[] = \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class;
$bundles[] = \Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle::class;
}
return $bundles;
}
示例6: __construct
/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
*/
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
parent::__construct('Symfony', Kernel::VERSION . ' - ' . $kernel->getName() . '/' . $kernel->getEnvironment() . ($kernel->isDebug() ? '/debug' : ''));
$this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
$this->getDefinition()->addOption(new InputOption('--process-isolation', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate processes.'));
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
}
示例7: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
if (!in_array($this->kernel->getEnvironment(), array('test', 'dev'))) {
$response = $event->getResponse();
$compressedContent = new HtmlCompressor($response->getContent());
$response->setContent($compressedContent->compress());
return $response;
}
}
示例8: getKernel
/**
* @return KernelInterface
*/
private function getKernel(InputInterface $input)
{
$env = $input->getParameterOption(['--env', '-e'], $this->baseKernel->getEnvironment());
$debug = !$input->hasParameterOption(['--no-debug', '']);
if ($env === $this->baseKernel->getEnvironment() && $debug === $this->baseKernel->isDebug()) {
return $this->baseKernel;
}
$kernelClass = new ReflectionClass($this->baseKernel);
return $kernelClass->newInstance([$env, $debug]);
}
示例9: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array('app_name' => $this->name, 'app_version' => $this->version, 'token' => $response->headers->get('X-Debug-Token'), 'symfony_version' => Kernel::VERSION, 'symfony_state' => 'unknown', 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a', 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a', 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', 'php_version' => PHP_VERSION, 'xdebug_enabled' => extension_loaded('xdebug'), 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'), 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'), 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'), 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'), 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'), 'bundles' => array(), 'sapi_name' => PHP_SAPI);
if (isset($this->kernel)) {
foreach ($this->kernel->getBundles() as $name => $bundle) {
$this->data['bundles'][$name] = $bundle->getPath();
}
$this->data['symfony_state'] = $this->determineSymfonyState();
}
}
示例10: populate
/**
* {@inheritdoc}
*/
public function populate(EntityManager $em = null)
{
$process = new Process(sprintf("%s/console fos:elastica:populate --env=%s", $this->kernel->getRootDir(), $this->kernel->getEnvironment()));
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
$this->output = $process->getOutput();
return $this;
}
示例11: getCoreBundlesClasses
private function getCoreBundlesClasses() : array
{
$bundles = [FrameworkBundle::class, SecurityBundle::class, TwigBundle::class, MonologBundle::class, SwiftmailerBundle::class, DoctrineBundle::class, DoctrineCacheBundle::class, DoctrineMigrationsBundle::class, DoctrineFixturesBundle::class, SensioFrameworkExtraBundle::class, FOSJsRoutingBundle::class, BazingaJsTranslationBundle::class, LiipImagineBundle::class, DoctrineBehaviorsBundle::class, CacheAdapterBundle::class, TwigCacheBundle::class];
if (in_array($this->kernel->getEnvironment(), ['dev', 'test'])) {
$bundles[] = WebProfilerBundle::class;
$bundles[] = SensioGeneratorBundle::class;
}
if (in_array($this->kernel->getEnvironment(), ['prod'])) {
$bundles[] = WebProfilerBundle::class;
}
return $bundles;
}
示例12: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->kernel->getEnvironment() === 'prod') {
$exception = $event->getException();
if ($exception instanceof HttpExceptionInterface) {
$status_code = $exception->getStatusCode();
} else {
$status_code = 500;
}
$response = new Response($this->getTwig()->render('rootiovmailmeBundle::error.html.twig', array('status_code' => $status_code)));
$event->setResponse($response);
}
}
示例13: populate
/**
* {@inheritdoc}
*/
public function populate(EntityManager $em = null)
{
$command = new PopulateCommand();
$command->setContainer($this->kernel->getContainer());
$output = new BufferedOutput();
$input = new ArgvInput(['env' => $this->kernel->getEnvironment()]);
if ($command->run($input, $output)) {
//return code is not zero
throw new \RuntimeException($output->fetch());
}
$this->output = $output->fetch();
return $this;
}
示例14: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ('prod' !== $this->kernel->getEnvironment()) {
return;
}
$exception = $event->getException();
$response = new Response();
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
if ($exception instanceof HttpExceptionInterface) {
if (400 < $exception->getStatusCode() && 500 > $exception->getStatusCode()) {
$response->setStatusCode(Response::HTTP_NOT_FOUND);
$response->headers->replace($exception->getHeaders());
}
}
$event->setResponse($response);
}
示例15: __construct
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
parent::__construct("Thelia", Thelia::THELIA_VERSION);
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
}