Forked from dmouse/SubRequestController.php
Last active
February 28, 2020 21:24
Revisions
-
Daveiano revised this gist
Feb 22, 2019 . 2 changed files with 16 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,28 +21,39 @@ class SubRequestController extends ControllerBase implements ContainerInjectionI */ protected $httpKernel; /** * @var \Symfony\Component\HttpFoundation\RequestStack */ protected $requestStack; /** * {@inheritdoc} */ public function __construct(HttpKernelInterface $http_kernel, RequestStack $request_stack) { $this->httpKernel = $http_kernel; $this->requestStack = $request_stack; } /** * Performs a subrequest. * * @param string $path * Path to use for subrequest. * @param string $method * The HTTP method to use, eg. Get, Post. * @param array $parameters * The query parameters. * @param string|resource|null $content * The raw body data. * * @return string * The response String. * * @throws \Exception */ public function subRequest($path, $method = 'GET', array $parameters = [], $content = NULL) { $sub_request = Request::create($path, $method, $parameters, $cookies = [], $files = [], $server = [], $content); $sub_request->setSession($this->requestStack->getCurrentRequest()->getSession()); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST, FALSE); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,8 @@ use Drupal\content_helper\Controller\SubRequestController; $httpKernel = \Drupal::service('http_kernel.basic'); $requestStack = \Drupal::requestStack(); $sub_request = new SubRequestController($httpKernel, $requestStack); $api_response = $sub_request->subRequest( '/jsonapi/field_config/field_config', -
Daveiano revised this gist
Feb 20, 2019 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <?php use Drupal\content_helper\Controller\SubRequestController; $httpKernel = \Drupal::service('http_kernel.basic'); $sub_request = new SubRequestController($httpKernel); $api_response = $sub_request->subRequest( '/jsonapi/field_config/field_config', [ 'filter' => [ 'bundle' => 'institution', 'entity_type' => 'node', ], 'page' => [ 'offset' => '50', ], ] ); -
Daveiano revised this gist
Feb 20, 2019 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,10 +44,9 @@ public function __construct(HttpKernelInterface $http_kernel) { public function subRequest($path, array $parameters = []) { $sub_request = Request::create($path, 'GET', $parameters); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST, FALSE); return $subResponse->getContent(); } } -
Daveiano revised this gist
Feb 20, 2019 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,17 +33,21 @@ public function __construct(HttpKernelInterface $http_kernel) { * * @param string $path * Path to use for subrequest. * @param array $parameters * The query parameters. * * @return string * The response String. * * @throws \Exception */ public function subRequest($path, array $parameters = []) { $sub_request = Request::create($path, 'GET', $parameters); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST); $subResponseContent = $subResponse->getContent(); return $subResponseContent; } } -
Daveiano revised this gist
Feb 11, 2019 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,17 +34,16 @@ public function __construct(HttpKernelInterface $http_kernel) { * @param string $path * Path to use for subrequest. * * @return string * The response String. * * @throws \Exception */ public function subRequest($path) { $sub_request = Request::create($path, 'GET'); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST); return $subResponse->getContent(); } } -
Daveiano revised this gist
Feb 11, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ namespace Drupal\content_helper\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; -
Daveiano revised this gist
Feb 11, 2019 . 1 changed file with 0 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,15 +29,6 @@ public function __construct(HttpKernelInterface $http_kernel) { $this->httpKernel = $http_kernel; } /** * Performs a subrequest. * -
Daveiano revised this gist
Feb 11, 2019 . 1 changed file with 6 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,18 @@ <?php namespace Drupal\content_helper\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; /** * Class SubRequest. * * @package Drupal\content_helper\Controller */ class SubRequestController extends ControllerBase implements ContainerInjectionInterface { /** -
Daveiano revised this gist
Feb 11, 2019 . 1 changed file with 17 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,26 +22,37 @@ class SubRequestController extends ControllerBase implements ContainerInjectionI * * @var Symfony\Component\HttpKernel\HttpKernelInterface */ protected $httpKernel; /** * {@inheritdoc} */ public function __construct(HttpKernelInterface $http_kernel) { $this->httpKernel = $http_kernel; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('http_kernel') ); } /** * Performs a subrequest. * * @param string $path * Path to use for subrequest. * * @return string $html * The response String. * * @throws \Exception */ public function subRequest($path) { $sub_request = Request::create($path, 'GET'); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST); $html = $subResponse->getContent(); -
dmouse revised this gist
Oct 6, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public static function create(ContainerInterface $container) { * Return Hello string. */ public function index() { $sub_request = Request::create('/search/node', 'GET'); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST); $html = $subResponse->getContent(); -
dmouse revised this gist
Oct 6, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,9 @@ class SubRequestController extends ControllerBase implements ContainerInjectionInterface { /** * Symfony\Component\HttpKernel\HttpKernelInterface definition. * * @var Symfony\Component\HttpKernel\HttpKernelInterface */ protected $http_kernel; -
dmouse created this gist
Oct 6, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ <?php /** * @file * Contains Drupal\dmouse\Controller\SubRequestController. * Generated by drupal/console. */ namespace Drupal\dmouse\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; class SubRequestController extends ControllerBase implements ContainerInjectionInterface { /** * Stack\StackedHttpKernel definition. * * @var Stack\StackedHttpKernel */ protected $http_kernel; public function __construct(HttpKernelInterface $http_kernel) { $this->httpKernel = $http_kernel; } public static function create(ContainerInterface $container) { return new static( $container->get('http_kernel') ); } /** * Index. * * @return string * Return Hello string. */ public function index() { $sub_request = Request::create('/user', 'GET'); $subResponse = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST); $html = $subResponse->getContent(); return $subResponse; } }