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

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

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