From ea4181166fa023e88c96c1311b972886a0636313 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 17 Jul 2017 16:56:01 +1200 Subject: [PATCH] FIX Ensure phpdbg calls are registered by SilverStripe core as a CLI call --- src/Control/Director.php | 2 +- tests/php/Control/DirectorTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index 9c9b29642..0790d0b99 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -944,7 +944,7 @@ class Director implements TemplateGlobalProvider */ public static function is_cli() { - return php_sapi_name() === "cli"; + return in_array(php_sapi_name(), ['cli', 'phpdbg']); } /** diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index e9fd2b741..3e6c58bde 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -761,4 +761,12 @@ class DirectorTest extends SapphireTest $this->assertEquals(2, $middleware->preCalls); $this->assertEquals(1, $specificMiddleware->postCalls); } + + /** + * If using phpdbg it returns itself instead of "cli" from php_sapi_name() + */ + public function testIsCli() + { + $this->assertTrue(Director::is_cli(), 'is_cli should be true for PHP CLI and phpdbg'); + } }