Skip to content
Permalink
Browse files

Use PHP_SAPI instead of php_sapi_name()

Shorter and Faster.
  • Loading branch information...
FrankFFFF committed Mar 27, 2015
1 parent 230b0e1 commit e499e38a18cc50c5e4f5caaa920db2b8aecf1445
@@ -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;
}
@@ -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)));
}
}
@@ -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)));
@@ -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();
@@ -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();
@@ -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 @@ 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();
}
@@ -304,7 +304,7 @@ public function start()
return true;
}
if ($this->_isCli) {
if ($this->_isCLI) {
$_SESSION = [];
return $this->_started = true;
}
@@ -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();
}
@@ -542,7 +542,7 @@ protected function _hasSession()
{
return !ini_get('session.use_cookies')
|| isset($_COOKIE[session_name()])
|| $this->_isCli;
|| $this->_isCLI;
}
/**
@@ -552,7 +552,7 @@ protected function _hasSession()
*/
public function renew()
{
if (!$this->_hasSession() || $this->_isCli) {
if (!$this->_hasSession() || $this->_isCLI) {
return;
}
@@ -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);
@@ -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);
@@ -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);
@@ -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.');
}
@@ -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');
}

0 comments on commit e499e38

Please sign in to comment.
You can’t perform that action at this time.