title: Is there a way of using CakeResponse Object in unconstructed Class?
body: <p>I'm currently doing a custom <strong>ErrorHandler</strong> for an App in <strong><em>CakePHP</em></strong>.
  The reason? Well, bots are always trying to find stuff in your servers and sometimes they provoke exceptions and or errors.</p>
  
  <p>The idea with this <strong>ErrorHandler</strong> is to filter requests and respond with the appropriate headers and prevent further request damage by handling this type of requests and make it transparent for the user client <em>(because it might affect JavaScript for instance)</em>.</p>
  
  <hr>
  
  <blockquote>
    <p>And what better way than to use the Framework's functionality, right?</p>
    
    <p>The thing is that since this ErrorHandler is being used statically,
    well, there is no constructor so nothing inherits anything, it doesn't
    matter if you instantiate any other <strong>CakePHP Object</strong>.</p>
    
    <p><strong>What would be the appropriate way to use CakeResponse Object?</strong></p>
  </blockquote>
  
  <hr>
  
  <h2>CakePHP's configuration:</h2>
  
  <p><strong>app/Config/bootstrap.php:</strong></p>
  
  <pre><code>App::uses('CustomErrorHandler', 'Lib');
  </code></pre>
  
  <p><strong>app/Config/core.php:</strong></p>
  
  <pre><code>// Error and exception handlers.
  Configure::write('Error', array(
      'handler' =&gt; 'CustomErrorHandler::handleError',
      'level' =&gt; E_ALL &amp; ~E_DEPRECATED,
      'trace' =&gt; true
  ));
  Configure::write('Exception', array(
      'handler' =&gt; 'CustomErrorHandler::handleException',
      'renderer' =&gt; 'ExceptionRenderer',
      'log' =&gt; true
  ));
  </code></pre>
  
  <p><strong>app/Lib/CustomErrorHandler.php:</strong></p>
  
  <pre><code>  ... rest of class code ...
  
    /**
     * Named after convention: This method receives all CakePHP's
     * errors and exceptions…
     *
     * @param  array $e The exception object.
     * @return mixed    Returns the error handling or header redirection.
     */
     public static function handleException($e)
     {
         $message = (string) $e-&gt;getMessage();
         $code    = (int)    $e-&gt;getCode();
         $file    = (string) $e-&gt;getFile();
         $line    = (string) $e-&gt;getLine();
  
         // If it's a Blacklist resource exception it will log it and redirect to home.
         if (self::__isResourceException($message))
         {
             return self::__dismissError();
         }
  
         return parent::handleException($e);
     }
  
    /**
     * This method redirects to home address using CakeResponse Object.
     *
     * @return mixed
     */
     private static function __dismissError()
     {
         return (new CakeResponse)-&gt;header(array(
             'Location' =&gt; self::$redirectUrl
         ));
     }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Will try a small layer over the ExceptionRenderer.</p>