Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Assertion/Handle.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Component\Assertion; | |
4 | |
5 /** | |
6 * Handler for runtime assertion failures. | |
7 * | |
8 * This class allows PHP 5.x to throw exceptions on runtime assertion fails | |
9 * in the same manner as PHP 7, and sets the ASSERT_EXCEPTION flag to TRUE | |
10 * for the PHP 7 runtime. | |
11 * | |
12 * @ingroup php_assert | |
13 */ | |
14 class Handle { | |
15 | |
16 /** | |
17 * Registers uniform assertion handling. | |
18 */ | |
19 public static function register() { | |
20 // Since we're using exceptions, turn error warnings off. | |
21 assert_options(ASSERT_WARNING, FALSE); | |
22 | |
23 if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) { | |
24 if (!class_exists('AssertionError', FALSE)) { | |
25 require __DIR__ . '/global_namespace_php5.php'; | |
26 } | |
27 // PHP 5 - create a handler to throw the exception directly. | |
28 assert_options(ASSERT_CALLBACK, function ($file = '', $line = 0, $code = '', $message = '') { | |
29 if (empty($message)) { | |
30 $message = $code; | |
31 } | |
32 throw new \AssertionError($message, 0, NULL, $file, $line); | |
33 }); | |
34 } | |
35 else { | |
36 // PHP 7 - just turn exception throwing on. | |
37 assert_options(ASSERT_EXCEPTION, TRUE); | |
38 } | |
39 } | |
40 | |
41 } |