manniru
1/28/2017 - 10:09 AM

custom drupal bootstrap (for performance)

custom drupal bootstrap (for performance)

<?php
if(empty($_GET['submithandler']) && empty($_POST['submithandler'])) {
  http_response_code(400);
  die('Invalid data');
}

define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);

require_once DRUPAL_ROOT. '/includes/bootstrap.inc';
require_once DRUPAL_ROOT. '/includes/common.inc';
require_once DRUPAL_ROOT. '/includes/file.inc';
require_once DRUPAL_ROOT. '/includes/theme.inc';

if(isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
  header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}


/**** angular ***/
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
/****  ***/


/****************************** sROUTING **************************************/


// Handle POST requests
switch($_GET['submithandler']) {

  case "my_custom_thingie":
    drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
    /**
        DRUPAL_BOOTSTRAP_CONFIGURATION,
    DRUPAL_BOOTSTRAP_PAGE_CACHE,
    DRUPAL_BOOTSTRAP_DATABASE,
    DRUPAL_BOOTSTRAP_VARIABLES,
    DRUPAL_BOOTSTRAP_SESSION,
    DRUPAL_BOOTSTRAP_PAGE_HEADER,
    DRUPAL_BOOTSTRAP_LANGUAGE,
    DRUPAL_BOOTSTRAP_FULL,
    */
    
    //If this is neede (not always)
   // module_load_all();
    //Do custom thing that only bootstraps db (for example)
    dako_search_ajax();
    break;

  default:
    http_response_code(400);
    die('Invalid data');
}