2016-05-09 07:40:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves an element from an associative array or %NULL if it is not
|
|
|
|
* defined.
|
2018-05-23 09:08:11 +00:00
|
|
|
*/
|
|
|
|
function nullif ($map, $key)
|
2016-05-09 07:40:46 +00:00
|
|
|
{
|
2018-05-23 09:08:11 +00:00
|
|
|
return isset($map[$key]) ? $map[$key] : NULL;
|
2016-05-09 07:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if passed $path is inside directory $dir.
|
2018-05-23 09:08:11 +00:00
|
|
|
*/
|
|
|
|
function checkFilePath($file, $path)
|
2016-05-09 07:40:46 +00:00
|
|
|
{
|
2018-05-23 09:08:11 +00:00
|
|
|
$checkPath = stream_resolve_include_path($path).'/';
|
|
|
|
$filePath = stream_resolve_include_path($checkPath.$file);
|
2016-05-09 07:40:46 +00:00
|
|
|
|
2018-05-23 09:08:11 +00:00
|
|
|
$len = strlen($checkPath);
|
|
|
|
return substr($filePath, 0, strlen($checkPath)) === $checkPath;
|
2016-05-09 07:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if passed token is hyphenized.
|
2018-05-23 09:08:11 +00:00
|
|
|
*/
|
|
|
|
function isHyphen($token) {
|
|
|
|
return preg_match('/^[\w\-]+$/', $token);
|
2016-05-09 07:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms an hyphen string to camelcase.
|
2018-05-23 09:08:11 +00:00
|
|
|
*/
|
|
|
|
function hyphenToCamelCase($string, $upperFirst = FALSE) {
|
|
|
|
$replaceFunc = function($matches) {
|
|
|
|
return strtoupper($matches[0][1]);
|
2016-05-09 07:40:46 +00:00
|
|
|
};
|
|
|
|
|
2018-05-23 09:08:11 +00:00
|
|
|
$result = preg_replace_callback('/-[a-z]/', $replaceFunc, $string);
|
2016-05-09 07:40:46 +00:00
|
|
|
|
|
|
|
if ($upperFirst)
|
2022-07-07 09:15:53 +00:00
|
|
|
$result = strtoupper($result[0]) . substr($result, 1);
|
2016-05-09 07:40:46 +00:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|