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.3 API

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

  • ErrorHandler
  • ExceptionRenderer

Exceptions

  • AclException
  • BadRequestException
  • CacheException
  • CakeBaseException
  • CakeException
  • CakeLogException
  • CakeSessionException
  • ConfigureException
  • ConsoleException
  • FatalErrorException
  • ForbiddenException
  • HttpException
  • InternalErrorException
  • MethodNotAllowedException
  • MissingActionException
  • MissingBehaviorException
  • MissingComponentException
  • MissingConnectionException
  • MissingControllerException
  • MissingDatabaseException
  • MissingDatasourceConfigException
  • MissingDatasourceException
  • MissingDispatcherFilterException
  • MissingHelperException
  • MissingLayoutException
  • MissingModelException
  • MissingPluginException
  • MissingShellException
  • MissingShellMethodException
  • MissingTableException
  • MissingTaskException
  • MissingTestLoaderException
  • MissingViewException
  • NotFoundException
  • NotImplementedException
  • PrivateActionException
  • RouterException
  • SocketException
  • UnauthorizedException
  • XmlException
  1: <?php
  2: /**
  3:  * Exceptions file. Contains the various exceptions CakePHP will throw until they are
  4:  * moved into their permanent location.
  5:  *
  6:  * PHP 5
  7:  *
  8:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 10:  *
 11:  * Licensed under The MIT License
 12:  * For full copyright and license information, please see the LICENSE.txt
 13:  * Redistributions of files must retain the above copyright notice.
 14:  *
 15:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 16:  * @link          http://book.cakephp.org/2.0/en/development/testing.html
 17:  * @package       Cake.Error
 18:  * @since         CakePHP(tm) v 2.0
 19:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 20:  */
 21: 
 22: /**
 23:  * Base class that all Exceptions extend.
 24:  *
 25:  * @package       Cake.Error
 26:  */
 27: class CakeBaseException extends RuntimeException {
 28: 
 29: /**
 30:  * Array of headers to be passed to CakeResponse::header()
 31:  *
 32:  * @var array
 33:  */
 34:     protected $_responseHeaders = null;
 35: 
 36: /**
 37:  * Get/set the response header to be used
 38:  *
 39:  * @param string|array $header. An array of header strings or a single header string
 40:  *  - an associative array of "header name" => "header value"
 41:  *  - an array of string headers is also accepted
 42:  * @param string $value. The header value.
 43:  * @return array
 44:  * @see CakeResponse::header()
 45:  */
 46:     public function responseHeader($header = null, $value = null) {
 47:         if ($header) {
 48:             if (is_array($header)) {
 49:                 return $this->_responseHeaders = $header;
 50:             }
 51:             $this->_responseHeaders = array($header => $value);
 52:         }
 53:         return $this->_responseHeaders;
 54:     }
 55: 
 56: }
 57: 
 58: /**
 59:  * Parent class for all of the HTTP related exceptions in CakePHP.
 60:  * All HTTP status/error related exceptions should extend this class so
 61:  * catch blocks can be specifically typed.
 62:  *
 63:  * @package       Cake.Error
 64:  */
 65: if (!class_exists('HttpException', false)) {
 66:     class HttpException extends CakeBaseException {
 67:     }
 68: }
 69: 
 70: /**
 71:  * Represents an HTTP 400 error.
 72:  *
 73:  * @package       Cake.Error
 74:  */
 75: class BadRequestException extends HttpException {
 76: 
 77: /**
 78:  * Constructor
 79:  *
 80:  * @param string $message If no message is given 'Bad Request' will be the message
 81:  * @param int $code Status code, defaults to 400
 82:  */
 83:     public function __construct($message = null, $code = 400) {
 84:         if (empty($message)) {
 85:             $message = 'Bad Request';
 86:         }
 87:         parent::__construct($message, $code);
 88:     }
 89: 
 90: }
 91: 
 92: /**
 93:  * Represents an HTTP 401 error.
 94:  *
 95:  * @package       Cake.Error
 96:  */
 97: class UnauthorizedException extends HttpException {
 98: 
 99: /**
100:  * Constructor
101:  *
102:  * @param string $message If no message is given 'Unauthorized' will be the message
103:  * @param int $code Status code, defaults to 401
104:  */
105:     public function __construct($message = null, $code = 401) {
106:         if (empty($message)) {
107:             $message = 'Unauthorized';
108:         }
109:         parent::__construct($message, $code);
110:     }
111: 
112: }
113: 
114: /**
115:  * Represents an HTTP 403 error.
116:  *
117:  * @package       Cake.Error
118:  */
119: class ForbiddenException extends HttpException {
120: 
121: /**
122:  * Constructor
123:  *
124:  * @param string $message If no message is given 'Forbidden' will be the message
125:  * @param int $code Status code, defaults to 403
126:  */
127:     public function __construct($message = null, $code = 403) {
128:         if (empty($message)) {
129:             $message = 'Forbidden';
130:         }
131:         parent::__construct($message, $code);
132:     }
133: 
134: }
135: 
136: /**
137:  * Represents an HTTP 404 error.
138:  *
139:  * @package       Cake.Error
140:  */
141: class NotFoundException extends HttpException {
142: 
143: /**
144:  * Constructor
145:  *
146:  * @param string $message If no message is given 'Not Found' will be the message
147:  * @param int $code Status code, defaults to 404
148:  */
149:     public function __construct($message = null, $code = 404) {
150:         if (empty($message)) {
151:             $message = 'Not Found';
152:         }
153:         parent::__construct($message, $code);
154:     }
155: 
156: }
157: 
158: /**
159:  * Represents an HTTP 405 error.
160:  *
161:  * @package       Cake.Error
162:  */
163: class MethodNotAllowedException extends HttpException {
164: 
165: /**
166:  * Constructor
167:  *
168:  * @param string $message If no message is given 'Method Not Allowed' will be the message
169:  * @param int $code Status code, defaults to 405
170:  */
171:     public function __construct($message = null, $code = 405) {
172:         if (empty($message)) {
173:             $message = 'Method Not Allowed';
174:         }
175:         parent::__construct($message, $code);
176:     }
177: 
178: }
179: 
180: /**
181:  * Represents an HTTP 500 error.
182:  *
183:  * @package       Cake.Error
184:  */
185: class InternalErrorException extends HttpException {
186: 
187: /**
188:  * Constructor
189:  *
190:  * @param string $message If no message is given 'Internal Server Error' will be the message
191:  * @param int $code Status code, defaults to 500
192:  */
193:     public function __construct($message = null, $code = 500) {
194:         if (empty($message)) {
195:             $message = 'Internal Server Error';
196:         }
197:         parent::__construct($message, $code);
198:     }
199: 
200: }
201: 
202: /**
203:  * CakeException is used a base class for CakePHP's internal exceptions.
204:  * In general framework errors are interpreted as 500 code errors.
205:  *
206:  * @package       Cake.Error
207:  */
208: class CakeException extends CakeBaseException {
209: 
210: /**
211:  * Array of attributes that are passed in from the constructor, and
212:  * made available in the view when a development error is displayed.
213:  *
214:  * @var array
215:  */
216:     protected $_attributes = array();
217: 
218: /**
219:  * Template string that has attributes sprintf()'ed into it.
220:  *
221:  * @var string
222:  */
223:     protected $_messageTemplate = '';
224: 
225: /**
226:  * Constructor.
227:  *
228:  * Allows you to create exceptions that are treated as framework errors and disabled
229:  * when debug = 0.
230:  *
231:  * @param string|array $message Either the string of the error message, or an array of attributes
232:  *   that are made available in the view, and sprintf()'d into CakeException::$_messageTemplate
233:  * @param int $code The code of the error, is also the HTTP status code for the error.
234:  */
235:     public function __construct($message, $code = 500) {
236:         if (is_array($message)) {
237:             $this->_attributes = $message;
238:             $message = __d('cake_dev', $this->_messageTemplate, $message);
239:         }
240:         parent::__construct($message, $code);
241:     }
242: 
243: /**
244:  * Get the passed in attributes
245:  *
246:  * @return array
247:  */
248:     public function getAttributes() {
249:         return $this->_attributes;
250:     }
251: 
252: }
253: 
254: /**
255:  * Missing Controller exception - used when a controller
256:  * cannot be found.
257:  *
258:  * @package       Cake.Error
259:  */
260: class MissingControllerException extends CakeException {
261: 
262:     protected $_messageTemplate = 'Controller class %s could not be found.';
263: 
264: //@codingStandardsIgnoreStart
265:     public function __construct($message, $code = 404) {
266:         parent::__construct($message, $code);
267:     }
268: //@codingStandardsIgnoreEnd
269: 
270: }
271: 
272: /**
273:  * Missing Action exception - used when a controller action
274:  * cannot be found.
275:  *
276:  * @package       Cake.Error
277:  */
278: class MissingActionException extends CakeException {
279: 
280:     protected $_messageTemplate = 'Action %s::%s() could not be found.';
281: 
282: //@codingStandardsIgnoreStart
283:     public function __construct($message, $code = 404) {
284:         parent::__construct($message, $code);
285:     }
286: //@codingStandardsIgnoreEnd
287: 
288: }
289: 
290: /**
291:  * Private Action exception - used when a controller action
292:  * starts with a  `_`.
293:  *
294:  * @package       Cake.Error
295:  */
296: class PrivateActionException extends CakeException {
297: 
298:     protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
299: 
300: //@codingStandardsIgnoreStart
301:     public function __construct($message, $code = 404, Exception $previous = null) {
302:         parent::__construct($message, $code, $previous);
303:     }
304: //@codingStandardsIgnoreEnd
305: 
306: }
307: 
308: /**
309:  * Used when a component cannot be found.
310:  *
311:  * @package       Cake.Error
312:  */
313: class MissingComponentException extends CakeException {
314: 
315:     protected $_messageTemplate = 'Component class %s could not be found.';
316: 
317: }
318: 
319: /**
320:  * Used when a behavior cannot be found.
321:  *
322:  * @package       Cake.Error
323:  */
324: class MissingBehaviorException extends CakeException {
325: 
326:     protected $_messageTemplate = 'Behavior class %s could not be found.';
327: 
328: }
329: 
330: /**
331:  * Used when a view file cannot be found.
332:  *
333:  * @package       Cake.Error
334:  */
335: class MissingViewException extends CakeException {
336: 
337:     protected $_messageTemplate = 'View file "%s" is missing.';
338: 
339: }
340: 
341: /**
342:  * Used when a layout file cannot be found.
343:  *
344:  * @package       Cake.Error
345:  */
346: class MissingLayoutException extends CakeException {
347: 
348:     protected $_messageTemplate = 'Layout file "%s" is missing.';
349: 
350: }
351: 
352: /**
353:  * Used when a helper cannot be found.
354:  *
355:  * @package       Cake.Error
356:  */
357: class MissingHelperException extends CakeException {
358: 
359:     protected $_messageTemplate = 'Helper class %s could not be found.';
360: 
361: }
362: 
363: /**
364:  * Runtime Exceptions for ConnectionManager
365:  *
366:  * @package       Cake.Error
367:  */
368: class MissingDatabaseException extends CakeException {
369: 
370:     protected $_messageTemplate = 'Database connection "%s" could not be found.';
371: 
372: }
373: 
374: /**
375:  * Used when no connections can be found.
376:  *
377:  * @package       Cake.Error
378:  */
379: class MissingConnectionException extends CakeException {
380: 
381:     protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
382: 
383:     public function __construct($message, $code = 500) {
384:         if (is_array($message)) {
385:             $message += array('enabled' => true);
386:         }
387:         parent::__construct($message, $code);
388:     }
389: 
390: }
391: 
392: /**
393:  * Used when a Task cannot be found.
394:  *
395:  * @package       Cake.Error
396:  */
397: class MissingTaskException extends CakeException {
398: 
399:     protected $_messageTemplate = 'Task class %s could not be found.';
400: 
401: }
402: 
403: /**
404:  * Used when a shell method cannot be found.
405:  *
406:  * @package       Cake.Error
407:  */
408: class MissingShellMethodException extends CakeException {
409: 
410:     protected $_messageTemplate = "Unknown command %1\$s %2\$s.\nFor usage try `cake %1\$s --help`";
411: 
412: }
413: 
414: /**
415:  * Used when a shell cannot be found.
416:  *
417:  * @package       Cake.Error
418:  */
419: class MissingShellException extends CakeException {
420: 
421:     protected $_messageTemplate = 'Shell class %s could not be found.';
422: 
423: }
424: 
425: /**
426:  * Exception class to be thrown when a datasource configuration is not found
427:  *
428:  * @package       Cake.Error
429:  */
430: class MissingDatasourceConfigException extends CakeException {
431: 
432:     protected $_messageTemplate = 'The datasource configuration "%s" was not found in database.php';
433: 
434: }
435: 
436: /**
437:  * Used when a datasource cannot be found.
438:  *
439:  * @package       Cake.Error
440:  */
441: class MissingDatasourceException extends CakeException {
442: 
443:     protected $_messageTemplate = 'Datasource class %s could not be found. %s';
444: 
445: }
446: 
447: /**
448:  * Exception class to be thrown when a database table is not found in the datasource
449:  *
450:  * @package       Cake.Error
451:  */
452: class MissingTableException extends CakeException {
453: 
454:     protected $_messageTemplate = 'Table %s for model %s was not found in datasource %s.';
455: 
456: }
457: 
458: /**
459:  * Exception raised when a Model could not be found.
460:  *
461:  * @package       Cake.Error
462:  */
463: class MissingModelException extends CakeException {
464: 
465:     protected $_messageTemplate = 'Model %s could not be found.';
466: 
467: }
468: 
469: /**
470:  * Exception raised when a test loader could not be found
471:  *
472:  * @package       Cake.Error
473:  */
474: class MissingTestLoaderException extends CakeException {
475: 
476:     protected $_messageTemplate = 'Test loader %s could not be found.';
477: 
478: }
479: 
480: /**
481:  * Exception raised when a plugin could not be found
482:  *
483:  * @package       Cake.Error
484:  */
485: class MissingPluginException extends CakeException {
486: 
487:     protected $_messageTemplate = 'Plugin %s could not be found.';
488: 
489: }
490: 
491: /**
492:  * Exception raised when a Dispatcher filter could not be found
493:  *
494:  * @package       Cake.Error
495:  */
496: class MissingDispatcherFilterException extends CakeException {
497: 
498:     protected $_messageTemplate = 'Dispatcher filter %s could not be found.';
499: 
500: }
501: 
502: /**
503:  * Exception class for AclComponent and Interface implementations.
504:  *
505:  * @package       Cake.Error
506:  */
507: class AclException extends CakeException {
508: }
509: 
510: /**
511:  * Exception class for Cache. This exception will be thrown from Cache when it
512:  * encounters an error.
513:  *
514:  * @package       Cake.Error
515:  */
516: class CacheException extends CakeException {
517: }
518: 
519: /**
520:  * Exception class for Router. This exception will be thrown from Router when it
521:  * encounters an error.
522:  *
523:  * @package       Cake.Error
524:  */
525: class RouterException extends CakeException {
526: }
527: 
528: /**
529:  * Exception class for CakeLog. This exception will be thrown from CakeLog when it
530:  * encounters an error.
531:  *
532:  * @package       Cake.Error
533:  */
534: class CakeLogException extends CakeException {
535: }
536: 
537: /**
538:  * Exception class for CakeSession. This exception will be thrown from CakeSession when it
539:  * encounters an error.
540:  *
541:  * @package       Cake.Error
542:  */
543: class CakeSessionException extends CakeException {
544: }
545: 
546: /**
547:  * Exception class for Configure. This exception will be thrown from Configure when it
548:  * encounters an error.
549:  *
550:  * @package       Cake.Error
551:  */
552: class ConfigureException extends CakeException {
553: }
554: 
555: /**
556:  * Exception class for Socket. This exception will be thrown from CakeSocket, CakeEmail, HttpSocket
557:  * SmtpTransport, MailTransport and HttpResponse when it encounters an error.
558:  *
559:  * @package       Cake.Error
560:  */
561: class SocketException extends CakeException {
562: }
563: 
564: /**
565:  * Exception class for Xml. This exception will be thrown from Xml when it
566:  * encounters an error.
567:  *
568:  * @package       Cake.Error
569:  */
570: class XmlException extends CakeException {
571: }
572: 
573: /**
574:  * Exception class for Console libraries. This exception will be thrown from Console library
575:  * classes when they encounter an error.
576:  *
577:  * @package       Cake.Error
578:  */
579: class ConsoleException extends CakeException {
580: }
581: 
582: /**
583:  * Represents a fatal error
584:  *
585:  * @package       Cake.Error
586:  */
587: class FatalErrorException extends CakeException {
588: 
589: /**
590:  * Constructor
591:  *
592:  * @param string $message
593:  * @param integer $code
594:  * @param string $file
595:  * @param integer $line
596:  */
597:     public function __construct($message, $code = 500, $file = null, $line = null) {
598:         parent::__construct($message, $code);
599:         if ($file) {
600:             $this->file = $file;
601:         }
602:         if ($line) {
603:             $this->line = $line;
604:         }
605:     }
606: 
607: }
608: 
609: /**
610:  * Not Implemented Exception - used when an API method is not implemented
611:  *
612:  * @package       Cake.Error
613:  */
614: class NotImplementedException extends CakeException {
615: 
616:     protected $_messageTemplate = '%s is not implemented.';
617: 
618: //@codingStandardsIgnoreStart
619:     public function __construct($message, $code = 501) {
620:         parent::__construct($message, $code);
621:     }
622: //@codingStandardsIgnoreEnd
623: 
624: }
625: 
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