PHP code example of pantheon-systems / smart_content_cdn
1. Go to this page and download the library: Download pantheon-systems/smart_content_cdn library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pantheon-systems / smart_content_cdn example snippets
php
// Get header data.
$smart_content_cdn = new HeaderData();
$p_obj = $smart_content_cdn->returnPersonalizationObject();
php
/**
* This method is called when the kernel.response is dispatched.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The dispatched event.
*/
public function onRespond(FilterResponseEvent $event) {
$config = \Drupal::configFactory()->get('smart_content_cdn.config');
// Check if Vary Header should be set.
if ($config->get('set_vary') ?? TRUE) {
$response = $event->getResponse();
// Header keys to add to Vary header.
$vary_headers = ['Audience', 'Interest', 'Role'];
// Retrieve and set vary header.
$smart_content_cdn = new HeaderData();
$response_vary_header = $smart_content_cdn->returnVaryHeader($vary_headers);
$response->headers->add($response_vary_header);
}
}