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


PHP RedirectResponse::prepare方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\RedirectResponse::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP RedirectResponse::prepare方法的具体用法?PHP RedirectResponse::prepare怎么用?PHP RedirectResponse::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\RedirectResponse的用法示例。


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

示例1: saveAction

 /**
  * @Route("/admin/asset/location-type/save")
  * @Method("POST")
  */
 public function saveAction(Request $request)
 {
     $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN', null, 'Unable to access this page!');
     $em = $this->getDoctrine()->getManager();
     $response = new Response();
     $locationTypes = [];
     $locationTypes['types'] = $em->getRepository('AppBundle\\Entity\\Asset\\LocationType')->findAll();
     $form = $this->createForm(LocationTypesType::class, $locationTypes, ['allow_extra_fields' => true]);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $locationTypes = $form->getData();
         foreach ($locationTypes['types'] as $type) {
             $em->persist($type);
         }
         $em->flush();
         $this->addFlash('notice', 'common.success');
         $response = new RedirectResponse($this->generateUrl('app_admin_asset_locationtype_index', [], UrlGeneratorInterface::ABSOLUTE_URL));
         $response->prepare($request);
         return $response->send();
     } else {
         $errorMessages = [];
         $formData = $form->all();
         foreach ($formData as $name => $item) {
             if (!$item->isValid()) {
                 $errorMessages[] = $name . ' - ' . $item->getErrors(true);
             }
         }
         return $this->render('admin/asset/location_types.html.twig', array('location_types_form' => $form->createView(), 'base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..')));
     }
 }
开发者ID:bgamrat,项目名称:crispy-octo-parakeet,代码行数:34,代码来源:LocationTypeController.php

示例2: handle

 /**
  * Handles an access denied failure redirecting to home page
  *
  * @param Request               $request
  * @param AccessDeniedException $accessDeniedException
  *
  * @return Response may return null
  */
 public function handle(Request $request, AccessDeniedException $accessDeniedException)
 {
     $this->logger->error('User tried to access: ' . $request->getUri());
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['message' => $accessDeniedException->getMessage(), 'trace' => $accessDeniedException->getTraceAsString(), 'exception' => get_class($accessDeniedException)], Response::HTTP_SERVICE_UNAVAILABLE);
     } else {
         $url = $request->getBasePath() !== "" ? $request->getBasePath() : "/";
         $response = new RedirectResponse($url);
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
         $response->prepare($request);
         return $response->send();
     }
 }
开发者ID:QuangDang212,项目名称:roadiz,代码行数:21,代码来源:AccessDeniedHandler.php

示例3: createFromRequest

 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:49,代码来源:DrupalKernel.php

示例4: prepareRedirectResponse

 /**
  * Creates a redirect response
  *
  * @param string  $url     URL to redirect to
  * @param integer $status  The status code (302 by default)
  * @param array   $headers An array of response headers (Location is always set to the given URL)
  * @return SymfonyRedirectResponse
  * @throws InvalidArgumentException
  */
 public function prepareRedirectResponse($url, $status = 302, array $headers = array())
 {
     $header_bag = $this->getHeaders();
     $header_bag->add($headers);
     $response = new SymfonyRedirectResponse($url, $status, $header_bag->all());
     $response->prepare($this->request);
     return $response;
 }
开发者ID:elgg,项目名称:elgg,代码行数:17,代码来源:ResponseFactory.php

示例5: createFromRequest

 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $kernel->initializeSettings($request);
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:35,代码来源:DrupalKernel.php

示例6: createFromRequest

 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $class_loader_class = get_class($class_loader);
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     // If the class loader is still the same, possibly upgrade to the APC class
     // loader.
     if ($class_loader_class == get_class($class_loader) && Settings::get('class_loader_auto_detect', TRUE) && function_exists('apc_fetch')) {
         $prefix = Settings::getApcuPrefix('class_loader', $core_root);
         $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader);
         $class_loader->unregister();
         $apc_loader->register();
         $class_loader = $apc_loader;
     }
     // Ensure that the class loader reference is up-to-date.
     $kernel->classLoader = $class_loader;
     return $kernel;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:61,代码来源:DrupalKernel.php


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