annotate core/lib/Drupal/Component/Assertion/Handle.php @ 19:fa3358dc1485 tip

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