Skip to main content

Process of page request to response in Drupal 8 - Part 1

For every drupal developer is it necessary to know the under the hood process of how drupal internally works and some of them may already know  page rendering process of drupal 7.

Lets see the Process of User Request to Response in  two parts:





PART 1:


Step 1:  The user make a request in the browser in the form of url for example: www.example.com


Step 2:  The browser will pass the request to the Web server where the website  resides(Here Drupal makes website...)

Step 3: In drupal , every request is handled via index.php file ,while digging into index file we may see the following lines as shown in the image.



Note:  Symfony is a playing a major role  in  drupal 8 and drupal 8 follows the object oriented style of programming..


Components used from symfony in drupal 8.




 So as you see , there is a two use statements 

1.use Drupal\Core\DrupalKernel
2.use Symfony\Component\Httpfoundation\Request.


Drupal and Symfony communicate between themselves to determine how an incoming HTTP request should be dealt with, to generate the response, and to deliver the response back to the browser.

Class DrupalKernel:


        This class is responsible for building the Dependency Injection Container and also deals with the registration of service providers. It allows registered service providers to add their services to the container.


DrupalKernel retrieves the Symfony HttpKernel and calls HttpKernel::handle($request).The HttpKernel::handle() method works internally by dispatching events.

Interacting to httpkernel is done via getHttpKernel method which in turn retrieves 
 the http_kernel service from the container.

To further information about httpkernel use this link HttpKernel

Class Request :
Request represents an HTTP request.

The methods dealing with URL accept / return a raw path (% encoded): * getBasePath * getBaseUrl * getPathInfo * getRequestUri * getUri * getUriForPath

$request = Request::createFromGlobals();


  1. $_GET
  2. $_POST
  3. $_SESSION
  4. $_REQUEST...etc

Creates a new request with values from PHP's super globals.

/ actually execute the kernel, which turns the request into a response
// by dispatching events, calling a controller, and returning the response
$response = $kernel->handle($request);


    Internally, the HttpKernel::handle() method first calls getController() on the controller resolver. This method is passed the Request and is responsible for somehow determining and returning a PHP callable (the controller) based on the request's information.



We will discuss the about response object further into part 2.











Comments

Popular posts from this blog

Comparison Between Drupal 7 and Drupal 8

Well in the learning process of drupal ........, This is my second post..if you missed previous article please refer the following  link. What is drupal and what is cms As i said in my pervious article ,drupal is an open source framework .We can easily download it from  Drupal  official link. As a extensive contibution of drupal community we are getting improved versions of drupal. Currently   Drupal 7 and Drupal 8 is activily maintained by the community. Lets find out the major difference between drupal 7 and drupal 8 Structure 1.Drupal 7 is based on procedural programming 2.Drupal 8 is  mainly focused on object oriented programming Template engine 1.Drupal 7 is based on the  php template engine 2.Drupal 8 is based on  twig template engine Routing 1.page callback functions are utilised  for each every page request   in drupal 7 2. Yml files are used to handle the routing configuration of the each p...

Why drupal is not fully object oriented ?

You can see module hooks are still in a procedural way to  utilize a dependent service  That's why we have a static  Drupal Class , it can get a service in a procedural context. How to access a service in module hooks? Drupal::service('{service id}') or  service accessors like Drupal::request(), Drupal::currentUser(), Drupal::entityManager(). It is providing a uniform way of getting any services inside hooks and it eases the transition from procedural code to injected oops code. How a container get services in drupal?  The container is built by the kernel  and passed to the static Drupal Class and the container gets all the services from the system by the below methods    1. \Drupal\Core\CoreServiceProvider    2.  the service providers of enabled modules     3. any other service providers defined in $GLOBALS['conf']['container_service_providers']. How you can improve the dependent service access from module ?  fu...

Hooks in Drupal

                  Hi All ,            For Every Drupal Developer initially get strucked with the concept of drupal is Hooks. It is the major driven approach in the old versions of drupal but  hooks are there in  drupal 8 too .                  Inorder to describe about  hook i dont want to explain with simple  statements or definitions. I assume that below points will make you clear in the concept of hooks in drupal 8. 1. Hooks occur at various points in the thread of execution, where Drupal seeks contributions from all the enabled modules. 2.A hook can be thought of as an event listener in the sense that an event triggers an action. The event in Drupal, such as deleting a node, would trigger the hook "hook_delete". 3.One way for modules to alter the core behavior of Drupal (or another module) is to use hooks. Hooks are specially-na...