You are here

public function Vcl::prepare_vcl in Fastly 7.2

Prepares VCL request.

Return value

array|bool

1 call to Vcl::prepare_vcl()
Vcl::execute in ./fastly.vcl.inc
Main execute function, takes values inserted into constructor, builds requests and sends them via Fastly API.

File

./fastly.vcl.inc, line 241

Class

Vcl
Class to control the VCL handling.

Code

public function prepare_vcl() {

  // Prepare VCL data content.
  $requests = array();
  foreach ($this->_vcl_data as $key => $single_vcl_data) {
    if (!empty($single_vcl_data['type'])) {

      // Append subdirectory to name if it exists.
      if (!empty($single_vcl_data['subdirectory'])) {
        $single_vcl_data['name'] = 'drupalmodule_' . $single_vcl_data['subdirectory'] . '_' . $single_vcl_data['type'];
        $single_vcl_data['vcl_dir'] = $single_vcl_data['vcl_dir'] . DIRECTORY_SEPARATOR . $single_vcl_data['subdirectory'];
        unset($single_vcl_data['subdirectory']);
      }
      else {
        $single_vcl_data['name'] = 'drupalmodule_' . $single_vcl_data['type'];
      }
      $single_vcl_data['dynamic'] = 0;
      $single_vcl_data['priority'] = 60;
      if (file_exists($single_vcl_data['vcl_dir'] . DIRECTORY_SEPARATOR . $single_vcl_data['type'] . '.vcl')) {
        $single_vcl_data['content'] = file_get_contents($single_vcl_data['vcl_dir'] . DIRECTORY_SEPARATOR . $single_vcl_data['type'] . '.vcl');
        unset($single_vcl_data['vcl_dir']);
      }
      else {
        $this
          ->add_error(t('VCL file does not exist.'));
        return FALSE;
      }
      if ($this
        ->check_if_vcl_exists($single_vcl_data['name'])) {
        $requests[] = $this
          ->prepare_update_vcl($single_vcl_data);
      }
      else {
        $requests[] = $this
          ->prepare_insert_vcl($single_vcl_data);
      }
    }
    else {
      $this
        ->add_error(t('VCL type not set.'));
      return FALSE;
    }
  }
  return $requests;
}