当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpKernel\Kernel类代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Kernel的典型用法代码示例。如果您正苦于以下问题:PHP Kernel类的具体用法?PHP Kernel怎么用?PHP Kernel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Kernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onLateKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onLateKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() or !in_array($this->kernel->getEnvironment(), array('admin', 'admin_dev'))) {
         return;
     }
     $this->translationListener->setTranslatableLocale($this->context->getDefaultFrontLocale());
 }
开发者ID:7rin0,项目名称:BigfootCoreBundle,代码行数:10,代码来源:KernelListener.php

示例2: onKernelException

 /**
  * Event handler that renders custom pages in case of a NotFoundHttpException (404)
  * or a AccessDeniedHttpException (403).
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ('dev' == $this->kernel->getEnvironment()) {
         return;
     }
     $exception = $event->getException();
     $this->request->setLocale($this->defaultLocale);
     $this->request->setDefaultLocale($this->defaultLocale);
     if ($exception instanceof NotFoundHttpException) {
         $section = $this->getExceptionSection(404, '404 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
         $response->setStatusCode(404);
         $event->setResponse($response);
     } elseif ($exception instanceof AccessDeniedHttpException) {
         $section = $this->getExceptionSection(403, '403 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
         $response->setStatusCode(403);
         $event->setResponse($response);
     }
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:35,代码来源:ExceptionListener.php

示例3: setUpDatabase

 /**
  * @before
  */
 public function setUpDatabase()
 {
     if (isset($_SERVER['IS_DOCTRINE_ORM_SUPPORTED']) && $_SERVER['IS_DOCTRINE_ORM_SUPPORTED']) {
         $this->entityManager = static::$sharedKernel->getContainer()->get('doctrine.orm.entity_manager');
         $this->purgeDatabase();
     }
 }
开发者ID:steffenbrem,项目名称:ApiTestCase,代码行数:10,代码来源:ApiTestCase.php

示例4: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $response = new JsonResponse();
     $detail = sprintf("Message: %s\nFile: %s:%s", $exception->getMessage(), $exception->getFile(), $exception->getLine());
     $data = ['type' => '#0', 'code' => 0, 'title' => 'Internal Server Error', 'status' => JsonResponse::HTTP_INTERNAL_SERVER_ERROR, 'detail' => $detail];
     $response->setStatusCode(JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
     $response->setData($data);
     if ($exception instanceof HttpExceptionInterface) {
         $response->headers->replace($exception->getHeaders());
     }
     if ($exception instanceof HttpException) {
         $data = ['type' => '#' . $exception->getCode(), 'code' => $exception->getCode(), 'title' => $exception->getMessage(), 'status' => JsonResponse::HTTP_BAD_REQUEST, 'detail' => $exception->getDetails()];
         $response->setStatusCode(JsonResponse::HTTP_BAD_REQUEST);
         $response->setData($data);
     }
     if ($exception instanceof AccessDeniedHttpException) {
         $event->setResponse(new Response("", 403));
     } else {
         $event->setResponse($response);
     }
     if (!in_array($this->kernel->getEnvironment(), array('dev', 'test'))) {
         unset($data['detail']);
     }
 }
开发者ID:reisraff,项目名称:symfony-api-util,代码行数:25,代码来源:ExceptionListener.php

示例5: loadBundleGenerators

 /**
  * Load the generators confirming to default naming rules in all bundles in the given Kernel.
  * @param Kernel $kernel
  */
 public function loadBundleGenerators(Kernel $kernel)
 {
     /** @var Bundle $bundle */
     foreach ($kernel->getBundles() as $bundle) {
         $this->loadGeneratorsForBundle($bundle);
     }
 }
开发者ID:tweedegolf,项目名称:generatorbundle,代码行数:11,代码来源:SymfonyGeneratorRegistry.php

示例6: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($this->kernel->getEnvironment() != "dev") {
         if (preg_match("/\\/api\\//", $event->getRequest()->getUri())) {
             $requestUri = $event->getRequest()->getUri();
             $requestMethod = $event->getRequest()->getMethod();
             if ($requestMethod !== "GET") {
                 $token = $this->context->getToken();
                 if (isset($token)) {
                     $user = $token->getUser();
                     if (!isset($user) || "anon." === $user) {
                         if (!$event->getRequest()->query->has('api_key')) {
                             $event->setResponse(new Response(json_encode(array("code" => 401, "message" => "The request requires user authentication")), 401));
                         }
                     }
                 } else {
                     $event->setResponse(new Response(json_encode(array("code" => 401, "message" => "The request requires user authentication")), 401));
                 }
             }
         }
     }
     $request = $event->getRequest();
     if (!count($request->request->all()) && in_array($request->getMethod(), array('POST', 'PUT', 'PATCH', 'DELETE'))) {
         $contentType = $request->headers->get('Content-Type');
         $format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType);
         if (!$this->decoderProvider->supports($format)) {
             return;
         }
         $decoder = $this->decoderProvider->getDecoder($format);
         $data = $decoder->decode($request->getContent(), $format);
         if (is_array($data)) {
             $request->request = new ParameterBag($data);
         }
     }
 }
开发者ID:holtchesley,项目名称:Zeega,代码行数:35,代码来源:ApiListener.php

示例7: pluginIs

 /**
  * @param bool $loaded
  * @param Kernel $kernel
  * @param string $pluginName
  */
 private function pluginIs($loaded, Kernel $kernel, $pluginName)
 {
     $this->assertSame($loaded, $kernel->getContainer()->hasParameter($pluginName . '.loaded'));
     $this->assertSame($loaded, $kernel->getContainer()->hasParameter($pluginName . '.build_was_called'));
     if ($kernel->getContainer()->has($pluginName . 'boot')) {
         $this->assertSame($loaded, $kernel->getContainer()->get($pluginName . '.boot')->wasCalled());
     }
 }
开发者ID:ad3n,项目名称:BundlePlugin,代码行数:13,代码来源:BundleWithPluginsTest.php

示例8: let

 public function let(IntentDocumentGeneratedEvent $event, RumGeneratorInterface $rumGenerator, Intent $intent, Kernel $kernel)
 {
     $this->event = $event;
     $this->rumGenerator = $rumGenerator;
     $this->intent = $intent;
     $this->kernel = $kernel;
     $this->event->getIntent()->willReturn($this->intent);
     $kernel->locateResource('@DonatePaymentBundle/Resources/public/img/sepa-template.jpg')->willReturn(__DIR__ . '/test.jpg');
     $this->beConstructedWith($rumGenerator, $kernel);
 }
开发者ID:bco-trey,项目名称:edonate,代码行数:10,代码来源:GenerateSepaPdfListenerSpec.php

示例9: __construct

 /**
  * CommandValidator constructor.
  *
  * @param Kernel $kernel
  */
 public function __construct(Kernel $kernel)
 {
     $this->_kernel = $kernel;
     $this->_app = new Application($kernel);
     foreach ($kernel->getBundles() as $bundle) {
         if ($bundle instanceof Bundle) {
             $bundle->registerCommands($this->_app);
         }
     }
 }
开发者ID:viscat,项目名称:PCCronManagerBundle,代码行数:15,代码来源:CommandValidator.php

示例10: getFilters

 public function getFilters()
 {
     $client = new \Mleko\ImageSqueeze\Client\Client();
     $squeeze = new \Twig_SimpleFilter('squeeze', function ($path) use($client) {
         $path = (string) $path;
         if (strlen($path) > 0 && $path[0] === '@') {
             $path = $this->kernel->locateResource($path);
         }
         if (file_exists($path)) {
             $inputFile = new \Mleko\ImageSqueeze\Client\File($path);
         } else {
             $inputFile = new \Mleko\ImageSqueeze\Client\File($path, $this->webRoot);
         }
         $pathHash = str_pad(base_convert(sha1($path), 16, 36), 31, '0', STR_PAD_LEFT);
         $compressedName = implode("/", str_split(substr($pathHash, 0, 6), 1)) . "/" . substr($pathHash, 6);
         if (false !== ($dotPosition = strrpos($path, "."))) {
             $compressedName .= substr($path, $dotPosition);
         }
         $newPath = '/cache/image/' . $compressedName;
         $fullPath = $this->webRoot . $newPath;
         if (!file_exists($fullPath)) {
             $newDir = dirname($fullPath);
             if (!file_exists($newDir)) {
                 mkdir($newDir, 0777, true);
             }
             return $client->shrink($inputFile)->toFile($newPath, $this->webRoot);
         }
         return new \Mleko\ImageSqueeze\Client\File($newPath, $this->webRoot);
     });
     return ['squeeze' => $squeeze];
 }
开发者ID:mleko,项目名称:image-squeeze-bundle,代码行数:31,代码来源:ImageSqueezeExtension.php

示例11: generatePdfFile

 /**
  * Generate PDF-file of ticket
  *
  * @param string $html       HTML to generate pdf
  * @param string $outputFile Name of output file
  *
  * @return mixed
  */
 public function generatePdfFile($html, $outputFile)
 {
     // Override default fonts directory for mPDF
     define('_MPDF_SYSTEM_TTFONTS', realpath($this->kernel->getRootDir() . '/../web/fonts/open-sans/') . '/');
     /** @var \TFox\MpdfPortBundle\Service\MpdfService $mPDFService */
     $mPDFService = $this->container->get('tfox.mpdfport');
     $mPDFService->setAddDefaultConstructorArgs(false);
     $constructorArgs = array('mode' => 'BLANK', 'format' => 'A5-L', 'margin_left' => 0, 'margin_right' => 0, 'margin_top' => 0, 'margin_bottom' => 0, 'margin_header' => 0, 'margin_footer' => 0);
     $mPDF = $mPDFService->getMpdf($constructorArgs);
     // Open Sans font settings
     $mPDF->fontdata['opensans'] = array('R' => 'OpenSans-Regular.ttf', 'B' => 'OpenSans-Bold.ttf', 'I' => 'OpenSans-Italic.ttf', 'BI' => 'OpenSans-BoldItalic.ttf');
     $mPDF->sans_fonts[] = 'opensans';
     $mPDF->available_unifonts[] = 'opensans';
     $mPDF->available_unifonts[] = 'opensansI';
     $mPDF->available_unifonts[] = 'opensansB';
     $mPDF->available_unifonts[] = 'opensansBI';
     $mPDF->default_available_fonts[] = 'opensans';
     $mPDF->default_available_fonts[] = 'opensansI';
     $mPDF->default_available_fonts[] = 'opensansB';
     $mPDF->default_available_fonts[] = 'opensansBI';
     $mPDF->SetDisplayMode('fullpage');
     $mPDF->WriteHTML($html);
     $pdfFile = $mPDF->Output($outputFile, 'S');
     return $pdfFile;
 }
开发者ID:jekakm,项目名称:fwdays,代码行数:33,代码来源:PdfGeneratorHelper.php

示例12: resolvePath

 private function resolvePath($file)
 {
     if (isset($this->config['aliases'][$file]['path'])) {
         return $this->kernel->getRootDir() . '/../web/' . $this->config['aliases'][$file]['path'];
     }
     return $file;
 }
开发者ID:burdanews,项目名称:twig-extensions-bundle,代码行数:7,代码来源:ResponsiveSvgExtension.php

示例13: locate

 /**
  * {@inheritdoc}
  */
 public function locate($resource, GeneratorInterface $generator)
 {
     $bundles = $this->kernel->getBundles();
     $class = get_class($generator);
     $appResources = $this->kernel->getContainer()->getParameter('kernel.root_dir') . '/Resources/';
     $location = "skeleton/{$generator->getName()}/{$resource}";
     /** @var Bundle $bundle */
     foreach ($bundles as $bundle) {
         if (strpos($class, $bundle->getNamespace()) !== false) {
             $global = "{$appResources}/{$bundle->getName()}/{$location}";
             if (file_exists($global) && is_readable($global)) {
                 return $global;
             } else {
                 $local = "{$bundle->getPath()}/Resources/{$location}";
                 if (file_exists($local) && is_readable($local)) {
                     return $local;
                 } else {
                     throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}");
                 }
             }
         }
     }
     $nonBundle = "{$appResources}{$location}";
     if (file_exists($nonBundle) && is_readable($nonBundle)) {
         return $nonBundle;
     }
     throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}");
 }
开发者ID:tweedegolf,项目名称:generatorbundle,代码行数:31,代码来源:SymfonyResourceLocator.php

示例14: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(RequestInterface $request)
 {
     $symfonyRequest = $request->getHttpFoundationRequest();
     $symfonyResponse = $this->kernel->handle($symfonyRequest);
     $this->kernel->terminate($symfonyRequest, $symfonyResponse);
     return $symfonyResponse;
 }
开发者ID:hason,项目名称:SpeedfonyBundle,代码行数:10,代码来源:KernelWrapper.php

示例15: findWebsocketClasses

 /**
  * @author Krzysztof Bednarczyk
  * @return string[]
  */
 public function findWebsocketClasses()
 {
     $dirs = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         if (in_array($bundle->getName(), $this->blackListedBundles)) {
             continue;
         }
         if (!is_dir($websocketDir = $bundle->getPath() . '/Websocket')) {
             continue;
         }
         $dirs[] = $websocketDir;
     }
     foreach (Finder::create()->name('*Websocket.php')->in($dirs)->files() as $file) {
         $filename = $file->getRealPath();
         if (!in_array($filename, $this->blackListedWebsocketFiles)) {
             require_once $filename;
         }
     }
     // It is not so important if these controllers never can be reached with
     // the current configuration nor whether they are actually controllers.
     // Important is only that we do not miss any classes.
     return array_filter(get_declared_classes(), function ($name) {
         return preg_match('/Websocket\\\\(.+)Websocket$/', $name) > 0;
     });
 }
开发者ID:bordeux,项目名称:websocket-bundle,代码行数:29,代码来源:RoutingManager.php


注:本文中的Symfony\Component\HttpKernel\Kernel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。