CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Exceptions

  • Exception
  • MissingPluginException
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * Redistributions of files must retain the above copyright notice.
  8:  *
  9:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 10:  * @since         3.0.0
 11:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 12:  */
 13: namespace Cake\Core\Exception;
 14: 
 15: use RuntimeException;
 16: 
 17: /**
 18:  * Base class that all CakePHP Exceptions extend.
 19:  */
 20: class Exception extends RuntimeException
 21: {
 22:     /**
 23:      * Array of attributes that are passed in from the constructor, and
 24:      * made available in the view when a development error is displayed.
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_attributes = [];
 29: 
 30:     /**
 31:      * Template string that has attributes sprintf()'ed into it.
 32:      *
 33:      * @var string
 34:      */
 35:     protected $_messageTemplate = '';
 36: 
 37:     /**
 38:      * Array of headers to be passed to Cake\Http\Response::header()
 39:      *
 40:      * @var array|null
 41:      */
 42:     protected $_responseHeaders;
 43: 
 44:     /**
 45:      * Default exception code
 46:      *
 47:      * @var int
 48:      */
 49:     protected $_defaultCode = 500;
 50: 
 51:     /**
 52:      * Constructor.
 53:      *
 54:      * Allows you to create exceptions that are treated as framework errors and disabled
 55:      * when debug mode is off.
 56:      *
 57:      * @param string|array $message Either the string of the error message, or an array of attributes
 58:      *   that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
 59:      * @param int|null $code The code of the error, is also the HTTP status code for the error.
 60:      * @param \Exception|null $previous the previous exception.
 61:      */
 62:     public function __construct($message = '', $code = null, $previous = null)
 63:     {
 64:         if ($code === null) {
 65:             $code = $this->_defaultCode;
 66:         }
 67: 
 68:         if (is_array($message)) {
 69:             $this->_attributes = $message;
 70:             $message = vsprintf($this->_messageTemplate, $message);
 71:         }
 72:         parent::__construct($message, $code, $previous);
 73:     }
 74: 
 75:     /**
 76:      * Get the passed in attributes
 77:      *
 78:      * @return array
 79:      */
 80:     public function getAttributes()
 81:     {
 82:         return $this->_attributes;
 83:     }
 84: 
 85:     /**
 86:      * Get/set the response header to be used
 87:      *
 88:      * See also Cake\Http\Response::withHeader()
 89:      *
 90:      * @param string|array|null $header An array of header strings or a single header string
 91:      *  - an associative array of "header name" => "header value"
 92:      *  - an array of string headers is also accepted (deprecated)
 93:      * @param string|null $value The header value.
 94:      * @return array
 95:      */
 96:     public function responseHeader($header = null, $value = null)
 97:     {
 98:         if ($header === null) {
 99:             return $this->_responseHeaders;
100:         }
101:         if (is_array($header)) {
102:             if (isset($header[0])) {
103:                 deprecationWarning(
104:                     'Passing a list string headers to Exception::responseHeader() is deprecated. ' .
105:                     'Use an associative array instead.'
106:                 );
107:             }
108: 
109:             return $this->_responseHeaders = $header;
110:         }
111:         $this->_responseHeaders = [$header => $value];
112:     }
113: }
114: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs