Michal M
Michal M

Reputation: 9480

How to overload shutdown function?

I am using Kohana (v3) framework but I believe it's not tied to a particular framework.

What I have is basically an app with a front-end, where I want to use Kohana's native Kohana::shutdown_handler(), but I also have a part of the - RESTful API - where I don't want colourful and html-encoded exception reporting. I want a plain text reporting.

The way I thought it might work is to register another shutdown function in API's controller abstract class constructor, but then I realised register_shutdown_function() works differently to set_exception_handler() and instead of replacing it adds another function to the shutdown procedure. What's worse PHP doesn't allow "unregistering" shutdown functions and that's where my problem lies.

What to do, if you want to use another shutdown function instead of one already registered?

Upvotes: 0

Views: 769

Answers (2)

Michal Kocián
Michal Kocián

Reputation: 26

You can simply overload

views/kohana/error
by your custom view and set

/**
 * Initialize Kohana, setting the default options.
 *
 * The following options are available:
 *
 * - string   base_url    path, and optionally domain, of your application   NULL
 * - string   index_file  name of your index file, usually "index.php"       index.php
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 */
Kohana::init(array(
 'base_url' => '/',
 'errors'   => FALSE,
));

Upvotes: 1

Bailey Parker
Bailey Parker

Reputation: 15903

The first thing that comes to mind would be to add your function before any other register_shutdown_function() calls and have it call any necessary shutdown functions and then call exit or die to immediately end the script without calling other shutdown functions. To ensure your call is first, I would make a separate file for it and add it as php.ini's auto_prepend_file.
Call it a hack...maybe. Does it work? I'm 99% sure it should.

Upvotes: 0

Related Questions