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

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