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