From: Florent Bruneau Date: Sun, 27 Feb 2011 18:38:13 +0000 (+0100) Subject: Enabler PHP natives assertion in debug and use Platal::assert() as a X-Git-Tag: core/1.1.3~10 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c4bcb1697481d3a6549f228739f17dc081641491;p=platal.git Enabler PHP natives assertion in debug and use Platal::assert() as a backend when assertions fail. Thus, you can write the following code: assert ('$toto != blah') If you run in debug mode, this will be evaluated and will raise an exception in case of error. If you run in production mode, this will juste be skipped. Signed-off-by: Florent Bruneau --- diff --git a/classes/plglobals.php b/classes/plglobals.php index d168037..fd11a25 100644 --- a/classes/plglobals.php +++ b/classes/plglobals.php @@ -135,6 +135,7 @@ class PlGlobals $this->baseurl = @trim($base .$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); $this->baseurl_http = @trim('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/'); } + assert_options(ASSERT_ACTIVE, $this->debug != 0); $this->setLocale(); } diff --git a/include/platal.inc.php b/include/platal.inc.php index 0f18429..900220c 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -144,7 +144,14 @@ function pl_print_errors($html = false) } } +function pl_assert_cb($file, $line, $message) +{ + Platal::assert(false, "Assertion failed at $file:$line with message: $message"); +} + set_error_handler('pl_error_handler', E_ALL | E_STRICT); +assert_options(ASSERT_CALLBACK, 'pl_assert_cb'); +assert_options(ASSERT_WARNING, false); if (php_sapi_name() == 'cli') { register_shutdown_function('pl_print_errors'); }