You are here

class Handle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/Assertion/Handle.php \Drupal\Component\Assertion\Handle

Handler for runtime assertion failures.

This class allows PHP 5.x to throw exceptions on runtime assertion fails in the same manner as PHP 7, and sets the ASSERT_EXCEPTION flag to TRUE for the PHP 7 runtime.

Hierarchy

  • class \Drupal\Component\Assertion\Handle

Expanded class hierarchy of Handle

Related topics

File

core/lib/Drupal/Component/Assertion/Handle.php, line 49
Contains \Drupal\Component\Assertion\Handle.

Namespace

Drupal\Component\Assertion
View source
class Handle {

  /**
   * Registers uniform assertion handling.
   */
  public static function register() {

    // Since we're using exceptions, turn error warnings off.
    assert_options(ASSERT_WARNING, FALSE);
    if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) {

      // PHP 5 - create a handler to throw the exception directly.
      assert_options(ASSERT_CALLBACK, function ($file = '', $line = 0, $code = '', $message = '') {
        if (empty($message)) {
          $message = $code;
        }
        throw new \AssertionError($message, 0, NULL, $file, $line);
      });
    }
    else {

      // PHP 7 - just turn exception throwing on.
      assert_options(ASSERT_EXCEPTION, TRUE);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Handle::register public static function Registers uniform assertion handling.