Skip to content

Commit 756b5d3

Browse files
authored
Merge pull request #13 from nguyenanhung/v3.1.14-develop
Optimize for PHP mbstring
2 parents 583f70e + b2234d3 commit 756b5d3

14 files changed

+154
-114
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"php": ">=5.6",
2222
"ext-json": "*",
2323
"ext-mbstring": "*",
24-
"nguyenanhung/codeigniter-basic-helper": ">=1.0"
24+
"nguyenanhung/codeigniter-basic-helper": ">=1.0",
25+
"symfony/polyfill-mbstring": ">=1.0"
2526
},
2627
"require-dev": {
2728
"nguyenanhung/my-debug": "^4.0 || ^3.0 || ^2.0 || ^1.0"
@@ -35,7 +36,8 @@
3536
"nguyenanhung\\CodeIgniter\\BaseREST\\": "thirdParty/REST/"
3637
},
3738
"files": [
38-
"helpers/codeigniter_modular.php"
39+
"helpers/codeigniter_modular.php",
40+
"helpers/common.php"
3941
]
4042
},
4143
"suggest": {

custom/HungNG_CI_Base_Controller_Filename_Checker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function checkFilename($filepath, $dir)
8686
$prefix = config_item('subclass_prefix');
8787

8888
if ($this->hasPrefix($filename, $prefix)) {
89-
$filename = substr($filename, strlen($prefix));
89+
$filename = substr($filename, bear_str_length($prefix));
9090
}
9191
}
9292

@@ -115,7 +115,7 @@ private function checkUcFirst($filename)
115115

116116
private function hasPrefix($filename, $prefix)
117117
{
118-
if (strncmp($prefix, $filename, strlen($prefix)) === 0) {
118+
if (strncmp($prefix, $filename, bear_str_length($prefix)) === 0) {
119119
return true;
120120
}
121121

helpers/common.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
if (!function_exists('bear_str_to_lower')) {
3+
function bear_str_to_lower($str)
4+
{
5+
if (function_exists('mb_strtolower')) {
6+
return mb_strtolower($str, 'UTF-8');
7+
}
8+
9+
return strtolower($str);
10+
}
11+
}
12+
if (!function_exists('bear_str_to_upper')) {
13+
function bear_str_to_upper($str)
14+
{
15+
if (function_exists('mb_strtoupper')) {
16+
return mb_strtoupper($str, 'UTF-8');
17+
}
18+
19+
return strtoupper($str);
20+
}
21+
}
22+
if (!function_exists('bear_str_length')) {
23+
function bear_str_length($str)
24+
{
25+
if (function_exists('mb_strlen')) {
26+
return mb_strlen($str);
27+
}
28+
29+
return strlen($str);
30+
}
31+
}

hungng/HungNG_CI_Base_Controllers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve
318318
{
319319
try {
320320
if (class_exists('Monolog\Logger') && class_exists('Monolog\Formatter\LineFormatter') && class_exists('Monolog\Handler\StreamHandler')) {
321-
$useLevel = strtolower($inputLevel);
321+
$useLevel = bear_str_to_lower($inputLevel);
322322
switch ($useLevel) {
323323
case 'debug':
324324
$keyLevel = Monolog\Logger::DEBUG;

hungng/HungNG_CI_Base_Lib_Hmvc_Migration.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function version($target_version)
279279

280280
// Filename validations
281281
if (preg_match('/^\d{3}_(\w+)$/', $name, $match)) {
282-
$match[1] = strtolower($match[1]);
282+
$match[1] = bear_str_to_lower($match[1]);
283283

284284
// Cannot repeat a migration at different steps
285285
if (in_array($match[1], $migrations)) {
@@ -325,7 +325,9 @@ public function version($target_version)
325325
// Loop through the migrations
326326
foreach ($migrations as $migration) {
327327
// Run the migration class
328-
$class = 'Migration_' . ucfirst(strtolower($migration));
328+
329+
$class = 'Migration_' . ucfirst(bear_str_to_lower($migration));
330+
329331
call_user_func(array(new $class, $method));
330332

331333
$current_version += $step;

hungng/HungNG_CI_Base_Lib_MongoDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ public function aggregate($collection, $operation)
14451445
public function order_by($fields = array())
14461446
{
14471447
foreach ($fields as $col => $val) {
1448-
if ($val == -1 || $val === false || strtolower($val) == 'desc') {
1448+
if ($val == -1 || $val === false || bear_str_to_lower($val) == 'desc') {
14491449
$this->sorts[$col] = -1;
14501450
} else {
14511451
$this->sorts[$col] = 1;
@@ -1603,7 +1603,7 @@ public function add_index($collection = "", $keys = array(), $options = array())
16031603
}
16041604

16051605
foreach ($keys as $col => $val) {
1606-
if ($val == -1 || $val === false || strtolower($val) == 'desc') {
1606+
if ($val == -1 || $val === false || bear_str_to_lower($val) == 'desc') {
16071607
$keys[$col] = -1;
16081608
} else {
16091609
$keys[$col] = 1;

hungng/HungNG_CI_Base_Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve
318318
{
319319
try {
320320
if (class_exists('Monolog\Logger') && class_exists('Monolog\Formatter\LineFormatter') && class_exists('Monolog\Handler\StreamHandler')) {
321-
$useLevel = strtolower($inputLevel);
321+
$useLevel = bear_str_to_lower($inputLevel);
322322
switch ($useLevel) {
323323
case 'debug':
324324
$keyLevel = Monolog\Logger::DEBUG;

0 commit comments

Comments
 (0)