Browse Source

Merge pull request #6184 from Fieah/PHP_SAPI

Use PHP_SAPI instead of php_sapi_name()
Mark Story 11 years ago
parent
commit
01c2c72da2

+ 1 - 1
src/Cache/Engine/XcacheEngine.php

@@ -58,7 +58,7 @@ class XcacheEngine extends CacheEngine
      */
     public function init(array $config = [])
     {
-        if (!extension_loaded('xcache') || php_sapi_name() === 'cli') {
+        if (PHP_SAPI === 'cli' || !extension_loaded('xcache')) {
             return false;
         }
 

+ 2 - 2
src/Core/functions.php

@@ -132,7 +132,7 @@ if (!function_exists('pr')) {
     function pr($var)
     {
         if (Configure::read('debug')) {
-            $template = php_sapi_name() !== 'cli' ? '<pre class="pr">%s</pre>' : "\n%s\n\n";
+            $template = PHP_SAPI !== 'cli' ? '<pre class="pr">%s</pre>' : "\n%s\n\n";
             printf($template, trim(print_r($var, true)));
         }
     }
@@ -156,7 +156,7 @@ if (!function_exists('pj')) {
         if (!Configure::read('debug')) {
             return;
         }
-        if (php_sapi_name() === 'cli') {
+        if (PHP_SAPI === 'cli') {
             printf("\n%s\n\n", trim(json_encode($var, JSON_PRETTY_PRINT)));
         } elseif (Configure::read('debug')) {
             printf('<pre class="pj">%s</pre>', trim(json_encode($var, JSON_PRETTY_PRINT)));

+ 2 - 2
src/Error/BaseErrorHandler.php

@@ -67,7 +67,7 @@ abstract class BaseErrorHandler
         set_error_handler([$this, 'handleError'], $level);
         set_exception_handler([$this, 'handleException']);
         register_shutdown_function(function () {
-            if (php_sapi_name() === 'cli') {
+            if (PHP_SAPI === 'cli') {
                 return;
             }
             $error = error_get_last();
@@ -264,7 +264,7 @@ abstract class BaseErrorHandler
                 $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
             }
         }
-        if (php_sapi_name() !== 'cli') {
+        if (PHP_SAPI !== 'cli') {
             $request = Router::getRequest();
             if ($request) {
                 $message .= "\nRequest URL: " . $request->here();

+ 6 - 6
src/Network/Session.php

@@ -60,7 +60,7 @@ class Session
      *
      * @var bool
      */
-    protected $_isCli = false;
+    protected $_isCLI = false;
 
     /**
      * Returns a new instance of a session after building a configuration bundle for it.
@@ -217,7 +217,7 @@ class Session
         }
 
         $this->_lifetime = ini_get('session.gc_maxlifetime');
-        $this->_isCli = php_sapi_name() === 'cli';
+        $this->_isCLI = PHP_SAPI === 'cli';
         session_register_shutdown();
     }
 
@@ -304,7 +304,7 @@ class Session
             return true;
         }
 
-        if ($this->_isCli) {
+        if ($this->_isCLI) {
             $_SESSION = [];
             return $this->_started = true;
         }
@@ -509,7 +509,7 @@ class Session
             $this->start();
         }
 
-        if (!$this->_isCli && session_status() === PHP_SESSION_ACTIVE) {
+        if (!$this->_isCLI && session_status() === PHP_SESSION_ACTIVE) {
             session_destroy();
         }
 
@@ -542,7 +542,7 @@ class Session
     {
         return !ini_get('session.use_cookies')
             || isset($_COOKIE[session_name()])
-            || $this->_isCli;
+            || $this->_isCLI;
     }
 
     /**
@@ -552,7 +552,7 @@ class Session
      */
     public function renew()
     {
-        if (!$this->_hasSession() || $this->_isCli) {
+        if (!$this->_hasSession() || $this->_isCLI) {
             return;
         }
 

+ 1 - 1
src/basics.php

@@ -73,7 +73,7 @@ HTML;
 
 TEXT;
         $template = $html;
-        if (php_sapi_name() === 'cli' || $showHtml === false) {
+        if (PHP_SAPI === 'cli' || $showHtml === false) {
             $template = $text;
             if ($showFrom) {
                 $lineInfo = sprintf('%s (line %s)', $file, $line);

+ 2 - 2
tests/TestCase/BasicsTest.php

@@ -295,7 +295,7 @@ EXPECTED;
 ###########################
 
 EXPECTED;
-        if (php_sapi_name() === 'cli') {
+        if (PHP_SAPI === 'cli') {
             $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
         } else {
             $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
@@ -320,7 +320,7 @@ EXPECTED;
 ###########################
 
 EXPECTED;
-        if (php_sapi_name() === 'cli') {
+        if (PHP_SAPI === 'cli') {
             $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
         } else {
             $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);

+ 1 - 1
tests/TestCase/Cache/Engine/ApcEngineTest.php

@@ -36,7 +36,7 @@ class ApcEngineTest extends TestCase
         parent::setUp();
         $this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');
 
-        if (php_sapi_name() === 'cli') {
+        if (PHP_SAPI === 'cli') {
             $this->skipIf(!ini_get('apc.enable_cli'), 'APC is not enabled for the CLI.');
         }
 

+ 3 - 0
tests/TestCase/Cache/Engine/XcacheEngineTest.php

@@ -35,6 +35,9 @@ class XcacheEngineTest extends TestCase
     public function setUp()
     {
         parent::setUp();
+        if (PHP_SAPI === 'cli') {
+            $this->markTestSkipped('Xcache is not available for the CLI.');
+        }
         if (!function_exists('xcache_set')) {
             $this->markTestSkipped('Xcache is not installed or configured properly');
         }