Skip to content

Intercepting All Responses

You can create an override to CEO's interceptor system that will run before all the other interceptors and run for every request. First, you have to create custom module.

Then, create a new global interceptor to run for all cached and uncached responses:

library/src/Interceptors/GlobalInterceptor.php:

<?php
namespace Tsn\Interceptors;

use Ceo\Http\Response;

/**
 * Example of a client global interceptor
 */
class GlobalInterceptor extends \Ceo\Interceptors\AllInterceptor
{
    public function afterRenderUncached($content)
    {
        $content = parent::afterRenderUncached($content);
        $this->response->setHeader('X-TSN-GBL', 'true');
        return $content;
    }

    public function afterRenderCached($content)
    {
        $content = parent::afterRenderCached($content);
        $this->response->setHeader('X-TSN-GBL', 'true');
        return $content;
    }
}

Then in your ceo-site.php config file, add the following line to the interceptors config:

...
    'view'          => [
        ...
        'interceptors'  => [
            'global'                         => '\Tsn\Interceptors\GlobalInterceptor',
            ...
        ]
    ]
...

Now that interceptor will run for every request.