CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.5 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.5
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • ConsoleErrorHandler
  • ConsoleInput
  • ConsoleInputArgument
  • ConsoleInputOption
  • ConsoleInputSubcommand
  • ConsoleOptionParser
  • ConsoleOutput
  • HelpFormatter
  • Shell
  • ShellDispatcher
  • TaskCollection
  1: <?php
  2: /**
  3:  * ErrorHandler for Console Shells
  4:  *
  5:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7:  *
  8:  * Licensed under The MIT License
  9:  * For full copyright and license information, please see the LICENSE.txt
 10:  * Redistributions of files must retain the above copyright notice.
 11:  *
 12:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 13:  * @link          http://cakephp.org CakePHP(tm) Project
 14:  * @since         CakePHP(tm) v 2.0
 15:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 16:  */
 17: 
 18: App::uses('ErrorHandler', 'Error');
 19: App::uses('ConsoleOutput', 'Console');
 20: App::uses('CakeLog', 'Log');
 21: 
 22: /**
 23:  * Error Handler for Cake console. Does simple printing of the
 24:  * exception that occurred and the stack trace of the error.
 25:  *
 26:  * @package       Cake.Console
 27:  */
 28: class ConsoleErrorHandler {
 29: 
 30: /**
 31:  * Standard error stream.
 32:  *
 33:  * @var ConsoleOutput
 34:  */
 35:     public static $stderr;
 36: 
 37: /**
 38:  * Get the stderr object for the console error handling.
 39:  *
 40:  * @return ConsoleOutput
 41:  */
 42:     public static function getStderr() {
 43:         if (empty(self::$stderr)) {
 44:             self::$stderr = new ConsoleOutput('php://stderr');
 45:         }
 46:         return self::$stderr;
 47:     }
 48: 
 49: /**
 50:  * Handle an exception in the console environment. Prints a message to stderr.
 51:  *
 52:  * @param Exception $exception The exception to handle
 53:  * @return void
 54:  */
 55:     public function handleException(Exception $exception) {
 56:         $stderr = self::getStderr();
 57:         $stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
 58:             $exception->getMessage(),
 59:             $exception->getTraceAsString()
 60:         ));
 61:         $code = $exception->getCode();
 62:         $code = ($code && is_int($code)) ? $code : 1;
 63:         return $this->_stop($code);
 64:     }
 65: 
 66: /**
 67:  * Handle errors in the console environment. Writes errors to stderr,
 68:  * and logs messages if Configure::read('debug') is 0.
 69:  *
 70:  * @param int $code Error code
 71:  * @param string $description Description of the error.
 72:  * @param string $file The file the error occurred in.
 73:  * @param int $line The line the error occurred on.
 74:  * @param array $context The backtrace of the error.
 75:  * @return void
 76:  */
 77:     public function handleError($code, $description, $file = null, $line = null, $context = null) {
 78:         if (error_reporting() === 0) {
 79:             return;
 80:         }
 81:         $stderr = self::getStderr();
 82:         list($name, $log) = ErrorHandler::mapErrorCode($code);
 83:         $message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
 84:         $stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));
 85: 
 86:         if (!Configure::read('debug')) {
 87:             CakeLog::write($log, $message);
 88:         }
 89: 
 90:         if ($log === LOG_ERR) {
 91:             return $this->_stop(1);
 92:         }
 93:     }
 94: 
 95: /**
 96:  * Wrapper for exit(), used for testing.
 97:  *
 98:  * @param int $code The exit code.
 99:  * @return void
100:  */
101:     protected function _stop($code = 0) {
102:         exit($code);
103:     }
104: 
105: }
106: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs