ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Assertion.php
Go to the documentation of this file.
1<?php
2
10{
11
12
17 private $assertion;
18
19
28 public function __construct($assertion = null)
29 {
30 assert($assertion === null || is_string($assertion));
31
32 $msg = 'Assertion failed: ' . var_export($assertion, true);
33 parent::__construct($msg);
34
35 $this->assertion = $assertion;
36 }
37
38
44 public function getAssertion()
45 {
46 return $this->assertion;
47 }
48
49
56 public static function installHandler()
57 {
58
59 assert_options(ASSERT_WARNING, 0);
60 assert_options(ASSERT_QUIET_EVAL, 0);
61 assert_options(ASSERT_CALLBACK, array('SimpleSAML_Error_Assertion', 'onAssertion'));
62 }
63
64
74 public static function onAssertion($file, $line, $message)
75 {
76
77 if (!empty($message)) {
78 $exception = new self($message);
79 } else {
80 $exception = new self();
81 }
82
83 $exception->logError();
84 }
85}
An exception for terminatinating execution or to throw for unit testing.
$assertion
The assertion which failed, or null if only an expression was passed to the assert-function.
Definition: Assertion.php:17
getAssertion()
Retrieve the assertion which failed.
Definition: Assertion.php:44
__construct($assertion=null)
Constructor for the assertion exception.
Definition: Assertion.php:28
static onAssertion($file, $line, $message)
Handle assertion.
Definition: Assertion.php:74
static installHandler()
Install this assertion handler.
Definition: Assertion.php:56
catch(Exception $e) $message