Skip to content

Commit 56f2cf1

Browse files
authored
Merge pull request #22 from nguyenanhung/v3.1.14-develop
V3.1.14 develop
2 parents d2c15b9 + 9ef438d commit 56f2cf1

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

hungng/HungNG_CI_Base_Queue_Worker.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class HungNG_CI_Base_Queue_Worker extends HungNG_CI_Base_Controllers
184184
public function __construct()
185185
{
186186
// CLI only
187-
if (php_sapi_name() != "cli") {
187+
if (PHP_SAPI !== "cli") {
188188
die('Access denied');
189189
}
190190

@@ -212,15 +212,15 @@ public function listen()
212212
}
213213

214214
// Pre-work check
215-
if (!method_exists($this, 'handleListen'))
216-
throw new Exception("You need to declare `handleListen()` method in your worker controller.", 500);
217-
if (!method_exists($this, 'handleWork'))
218-
throw new Exception("You need to declare `handleWork()` method in your worker controller.", 500);
219-
if ($this->logPath && !file_exists($this->logPath)) {
220-
// Try to access or create log file
221-
if ($this->_log('')) {
222-
throw new Exception("Log file doesn't exist: `" . $this->logPath . "`.", 500);
223-
}
215+
if (!method_exists($this, 'handleListen')) {
216+
throw new \RuntimeException("You need to declare `handleListen()` method in your worker controller.", 500);
217+
}
218+
if (!method_exists($this, 'handleWork')) {
219+
throw new \RuntimeException("You need to declare `handleWork()` method in your worker controller.", 500);
220+
}
221+
// Try to access or create log file
222+
if ($this->logPath && !file_exists($this->logPath) && $this->_log('')) {
223+
throw new \RuntimeException("Log file doesn't exist: `" . $this->logPath . "`.", 500);
224224
}
225225

226226
// INI setting
@@ -233,8 +233,8 @@ public function listen()
233233
// Worker command builder
234234
// Be careful to avoid infinite loop by opening listener itself
235235
$workerAction = 'work';
236-
$route = $this->router->fetch_directory() . $this->router->fetch_class() . "/{$workerAction}";
237-
$workerCmd = "{$this->phpCommand} " . FCPATH . "index.php {$route}";
236+
$route = $this->router->fetch_directory() . $this->router->fetch_class() . "/" . $workerAction;
237+
$workerCmd = $this->phpCommand . " " . FCPATH . "index.php " . $route;
238238

239239
// Static variables
240240
$startTime = 0;
@@ -333,8 +333,9 @@ public function listen()
333333
public function work($id = 1)
334334
{
335335
// Pre-work check
336-
if (!method_exists($this, 'handleWork'))
337-
throw new Exception("You need to declare `handleWork()` method in your worker controller.", 500);
336+
if (!method_exists($this, 'handleWork')) {
337+
throw new \RuntimeException("You need to declare `handleWork()` method in your worker controller.", 500);
338+
}
338339

339340
// INI setting
340341
if ($this->debug) {
@@ -439,8 +440,9 @@ public function launch($action = 'listen')
439440
public function single($force = false)
440441
{
441442
// Pre-work check
442-
if (!method_exists($this, 'handleSingle'))
443-
throw new Exception("You need to declare `handleSingle()` method in your worker controller.", 500);
443+
if (!method_exists($this, 'handleSingle')) {
444+
throw new \RuntimeException("You need to declare `handleSingle()` method in your worker controller.", 500);
445+
}
444446

445447
// Shared lock flag builder
446448
$lockFile = sys_get_temp_dir() . "/yidas-codeiginiter-queue-worker_" . str_replace('/', '_', $this->router->fetch_directory()) . get_called_class() . '.lock';
@@ -457,7 +459,7 @@ public function single($force = false)
457459

458460
// Start Single - Set identified lock
459461
// Close Single - Release identified lock
460-
register_shutdown_function(function() use ($lockFile) {
462+
register_shutdown_function(function () use ($lockFile) {
461463
@unlink($lockFile);
462464
});
463465

@@ -593,9 +595,11 @@ protected function _log($textLine, $logPath = null)
593595

594596
$logPath = ($logPath) ? $logPath : $this->logPath;
595597

596-
if ($logPath)
597-
return file_put_contents($logPath, $this->_formatTextLine($textLine), FILE_APPEND); else
598-
return false;
598+
if ($logPath) {
599+
return file_put_contents($logPath, $this->_formatTextLine($textLine), FILE_APPEND);
600+
}
601+
602+
return false;
599603
}
600604

601605
/**
@@ -633,9 +637,9 @@ protected function _isPidAlive($pid)
633637
{
634638
if (((function_exists('posix_getpgid') && posix_getpgid($pid)) || file_exists("/proc/{$pid}"))) {
635639
return true;
636-
} else {
637-
return false;
638640
}
641+
642+
return false;
639643
}
640644

641645
/**
@@ -648,9 +652,9 @@ protected function _isLinux()
648652
// Just make sure that it's not Windows
649653
if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
650654
return false;
651-
} else {
652-
return true;
653655
}
656+
657+
return true;
654658
}
655659

656660
/**

system/core/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public function set_cookie($name, $value = '', $expire = '', $domain = '', $path
366366
if (is_array($name))
367367
{
368368
// always leave 'name' in last place, as the loop will break otherwise, due to $$item
369-
foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name', 'samesite') as $item)
369+
foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'samesite', 'name') as $item)
370370
{
371371
if (isset($name[$item]))
372372
{

system/core/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function csrf_set_cookie()
297297
header('Set-Cookie: ' . $this->_csrf_cookie_name . '=' . $this->_csrf_hash
298298
. '; Expires=' . gmdate('D, d-M-Y H:i:s T', $expire)
299299
. '; Max-Age=' . $this->_csrf_expire
300-
. '; Path=' . rawurlencode(config_item('cookie_path'))
300+
. '; Path='.implode('/', array_map('rawurlencode', explode('/', config_item('cookie_path'))))
301301
. ($domain === '' ? '' : '; Domain=' . $domain)
302302
. ($secure_cookie ? '; Secure' : '')
303303
. (config_item('cookie_httponly') ? '; HttpOnly' : '')

system/libraries/Cache/drivers/Cache_redis.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class CI_Cache_redis extends CI_Driver
6060
'host' => '127.0.0.1',
6161
'password' => NULL,
6262
'port' => 6379,
63-
'timeout' => 0
63+
'timeout' => 0.0,
64+
'database' => 0
6465
);
6566

6667
/**

system/libraries/Pagination.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function create_links()
523523
}
524524

525525
// If something isn't quite right, back to the default base page.
526-
if ( ! ctype_digit($this->cur_page) OR ($this->use_page_numbers && (int) $this->cur_page === 0))
526+
if ( ! ctype_digit((string) $this->cur_page) OR ($this->use_page_numbers && (int) $this->cur_page === 0))
527527
{
528528
$this->cur_page = $base_page;
529529
}

system/libraries/Session/drivers/Session_redis_driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function __construct(&$params)
157157
{
158158
$save_path['password'] = preg_match('#auth=([^\s&]+)#', $matches['options'], $match) ? $match[1] : NULL;
159159
$save_path['database'] = preg_match('#database=(\d+)#', $matches['options'], $match) ? (int) $match[1] : NULL;
160-
$save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : NULL;
160+
$save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : 0.0;
161161

162162
preg_match('#prefix=([^\s&]+)#', $matches['options'], $match) && $this->_key_prefix = $match[1];
163163
}

0 commit comments

Comments
 (0)