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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
 24:      * Array of attributes that are passed in from the constructor, and
 25:      * made available in the view when a development error is displayed.
 26:      *
 27:      * @var array
 28:      */
 29:     protected $_attributes = [];
 30: 
 31:     /**
 32:      * Template string that has attributes sprintf()'ed into it.
 33:      *
 34:      * @var string
 35:      */
 36:     protected $_messageTemplate = '';
 37: 
 38:     /**
 39:      * Array of headers to be passed to Cake\Http\Response::header()
 40:      *
 41:      * @var array|null
 42:      */
 43:     protected $_responseHeaders;
 44: 
 45:     /**
 46:      * Default exception code
 47:      *
 48:      * @var int
 49:      */
 50:     protected $_defaultCode = 500;
 51: 
 52:     /**
 53:      * Constructor.
 54:      *
 55:      * Allows you to create exceptions that are treated as framework errors and disabled
 56:      * when debug = 0.
 57:      *
 58:      * @param string|array $message Either the string of the error message, or an array of attributes
 59:      *   that are made available in the view, and sprintf()'d into Exception::$_messageTemplate
 60:      * @param int|null $code The code of the error, is also the HTTP status code for the error.
 61:      * @param \Exception|null $previous the previous exception.
 62:      */
 63:     public function __construct($message = '', $code = null, $previous = null)
 64:     {
 65:         if ($code === null) {
 66:             $code = $this->_defaultCode;
 67:         }
 68: 
 69:         if (is_array($message)) {
 70:             $this->_attributes = $message;
 71:             $message = vsprintf($this->_messageTemplate, $message);
 72:         }
 73:         parent::__construct($message, $code, $previous);
 74:     }
 75: 
 76:     /**
 77:      * Get the passed in attributes
 78:      *
 79:      * @return array
 80:      */
 81:     public function getAttributes()
 82:     {
 83:         return $this->_attributes;
 84:     }
 85: 
 86:     /**
 87:      * Get/set the response header to be used
 88:      *
 89:      * See also Cake\Http\Response::withHeader()
 90:      *
 91:      * @param string|array|null $header An array of header strings or a single header string
 92:      *  - an associative array of "header name" => "header value"
 93:      *  - an array of string headers is also accepted (deprecated)
 94:      * @param string|null $value The header value.
 95:      * @return array
 96:      */
 97:     public function responseHeader($header = null, $value = null)
 98:     {
 99:         if ($header === null) {
100:             return $this->_responseHeaders;
101:         }
102:         if (is_array($header)) {
103:             if (isset($header[0])) {
104:                 deprecationWarning(
105:                     'Passing a list string headers to Exception::responseHeader() is deprecated. ' .
106:                     'Use an associative array instead.'
107:                 );
108:             }
109: 
110:             return $this->_responseHeaders = $header;
111:         }
112:         $this->_responseHeaders = [$header => $value];
113:     }
114: }
115: 
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