diff options
Diffstat (limited to 'it.class')
| -rw-r--r-- | it.class | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -25,7 +25,6 @@ static $error_context; # Callback, can provide $p params like 'head' and 'toscre /** * Create config class with static members initialized (e.g. $home). - * NOTE: PHP5 ONLY * @param $p Static members to be generated in newly created class * service: Class name of created class (default: from caller path) * home: Home directory of application (default: from caller path) @@ -44,6 +43,10 @@ static function createconfig($p = array()) 'service' => $parts[2], ); + # Add credentials from service's "var/credentials" as static members so they don't need to be in git + foreach (it::match('(\w+)\s*=\s*["\']?(.*?)["\']?$', @it::file_get_contents($GLOBALS['ULTRAHOME'] . "/var/credentials"), ['multiline' => true, 'all' => true]) as $env) + $p += [$env[0] => $env[1]]; + if (class_exists($p['service'] . "_tools")) $extends = "extends {$p['service']}_tools "; @@ -601,7 +604,7 @@ static function any2utf8($value, $errprefix = "") } else if (is_string($value)) { - if (!is_int(grapheme_strlen($value))) + if (!mb_check_encoding($value, "UTF-8")) list($value, $error) = array(it::utf8_encode($value), it::utf8_encode("incorrect utf8-encoding. input=$value")); if (preg_match('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', $value)) list($value, $error) = array(it::any2utf8(preg_replace_callback('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', function($m) {return it::utf8_decode($m[0]);}, $value)), $errprefix ? "double utf8-encoding. input=$value" : ""); @@ -609,8 +612,8 @@ static function any2utf8($value, $errprefix = "") list($value, $error) = array(preg_replace('/\xef\xb7[\x90-\xaf]|\xef\xbf[\xbe\xbf]/', " ", $value), "forbidden utf-8 character. input=$value"); $value = preg_replace('/\xc2\xad/', '', $value); # Kill invisible soft hyphens $value = normalizer_normalize($value, Normalizer::FORM_C); - if (preg_match('/^\pM/u', $value)) # Remove combining characters (e.g. U+0338 "Combining Long Solidus Overlay") at beginning of string - list($value, $error) = array(preg_replace('/^\pM+/u', "", $value), "combining character at beginning of string. input=$value"); + if (preg_match('/(^| )\pM/u', $value)) # Remove combining characters (e.g. U+0338 "Combining Long Solidus Overlay") at start of after blank + list($value, $error) = array(preg_replace('/(^| )\pM+/u', '$1', $value), "combining character at beginning of string. input=$value"); if ($error && $errprefix) it::error(array('title' => "$errprefix: " . trim($error))); } @@ -623,7 +626,7 @@ static function any2utf8($value, $errprefix = "") */ static function ucfirst($string) { - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); + return mb_ucfirst($string); } /** @@ -631,7 +634,7 @@ static function ucfirst($string) */ static function lcfirst($string) { - return mb_strtolower(mb_substr($string, 0, 1)) . mb_substr($string, 1); + return mb_lcfirst($string); } /** @@ -639,7 +642,7 @@ static function lcfirst($string) */ static function ucwords($string) { - return preg_replace_callback('/\b\w/u', function($m) { return mb_strtoupper($m[0]); }, mb_strtolower($string)); + return mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); } static function substr_replace($string, $replacement, $start, $length) |