Skip to content

Commit

Permalink
Merge pull request #6184 from Fieah/PHP_SAPI
Browse files Browse the repository at this point in the history
Use PHP_SAPI instead of php_sapi_name()
  • Loading branch information
markstory committed Mar 28, 2015
2 parents 80e2008 + e499e38 commit 01c2c72
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Cache/Engine/XcacheEngine.php
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/functions.php
Expand Up @@ -132,7 +132,7 @@ function namespaceSplit($class)
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)));
}
}
Expand All @@ -156,7 +156,7 @@ function pj($var)
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)));
Expand Down
4 changes: 2 additions & 2 deletions src/Error/BaseErrorHandler.php
Expand Up @@ -67,7 +67,7 @@ public function register()
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();
Expand Down Expand Up @@ -264,7 +264,7 @@ protected function _getMessage(\Exception $exception)
$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();
Expand Down
12 changes: 6 additions & 6 deletions src/Network/Session.php
Expand Up @@ -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.
Expand Down Expand Up @@ -217,7 +217,7 @@ public function __construct(array $config = [])
}

$this->_lifetime = ini_get('session.gc_maxlifetime');
$this->_isCli = php_sapi_name() === 'cli';
$this->_isCLI = PHP_SAPI === 'cli';
session_register_shutdown();
}

Expand Down Expand Up @@ -304,7 +304,7 @@ public function start()
return true;
}

if ($this->_isCli) {
if ($this->_isCLI) {
$_SESSION = [];
return $this->_started = true;
}
Expand Down Expand Up @@ -509,7 +509,7 @@ public function destroy()
$this->start();
}

if (!$this->_isCli && session_status() === PHP_SESSION_ACTIVE) {
if (!$this->_isCLI && session_status() === PHP_SESSION_ACTIVE) {
session_destroy();
}

Expand Down Expand Up @@ -542,7 +542,7 @@ protected function _hasSession()
{
return !ini_get('session.use_cookies')
|| isset($_COOKIE[session_name()])
|| $this->_isCli;
|| $this->_isCLI;
}

/**
Expand All @@ -552,7 +552,7 @@ protected function _hasSession()
*/
public function renew()
{
if (!$this->_hasSession() || $this->_isCli) {
if (!$this->_hasSession() || $this->_isCLI) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/basics.php
Expand Up @@ -73,7 +73,7 @@ function debug($var, $showHtml = null, $showFrom = true)
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);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/BasicsTest.php
Expand Up @@ -295,7 +295,7 @@ public function testDebug()
###########################
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);
Expand All @@ -320,7 +320,7 @@ public function testDebug()
###########################
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Cache/Engine/ApcEngineTest.php
Expand Up @@ -36,7 +36,7 @@ public function setUp()
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.');
}

Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Cache/Engine/XcacheEngineTest.php
Expand Up @@ -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');
}
Expand Down

0 comments on commit 01c2c72

Please sign in to comment.