diff options
Diffstat (limited to '')
-rw-r--r-- | lib/Exceptions.php | 1 | ||||
-rw-r--r-- | lib/command-helper.php | 15 | ||||
-rw-r--r-- | lib/helper.php | 41 |
3 files changed, 55 insertions, 2 deletions
diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 2e9109b..83bd380 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -10,3 +10,4 @@ set_error_handler("exception_error_handler"); class NotFoundException extends Exception {} class ScheduleException extends Exception {} +class ConfigException extends Exception {} diff --git a/lib/command-helper.php b/lib/command-helper.php new file mode 100644 index 0000000..c406b9e --- /dev/null +++ b/lib/command-helper.php @@ -0,0 +1,15 @@ +<?php + +function stderr($str) { + $args = func_get_args(); + $args[0] = $args[0]."\n"; + array_unshift($args, STDERR); + call_user_func_array('fprintf', $args); +} + +function stdout($str) { + $args = func_get_args(); + $args[0] = $args[0]."\n"; + array_unshift($args, STDOUT); + call_user_func_array('fprintf', $args); +} diff --git a/lib/helper.php b/lib/helper.php index 4fce91e..1925382 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -18,14 +18,20 @@ function baseurl() if(startswith('//', $base)) $base = proto().':'.$base; - return forceslash(forceslash($base).@$GLOBALS['MANDATOR']); + return forceslash($base); } $base = ssl() ? 'https://' : 'http://'; $base .= $_SERVER['HTTP_HOST']; $base .= forceslash(dirname($_SERVER['SCRIPT_NAME'])); - return forceslash(forceslash($base).@$GLOBALS['MANDATOR']); + return forceslash($base); +} + +function joinpath($parts) +{ + $parts = array_map('forceslash', $parts); + return rtrim(implode('', $parts), '/'); } function forceslash($url) @@ -108,3 +114,34 @@ function url_params() return ''; } + +/** + * returns the fielst element matching $predicate or null, if none matched. + * $predicate is a callable that receives one array value at a time and can + * return a bool'ish value + */ +function array_filter_first($array, $predicate) +{ + foreach ($array as $value) { + if( $predicate($value) ) { + return $value; + } + } + + return null; +} +/** + * returns the fielst element matching $predicate or null, if none matched. + * $predicate is a callable that receives one array value at a time and can + * return a bool'ish value + */ +function array_filter_last($array, $predicate) +{ + foreach (array_reverse($array) as $value) { + if( $predicate($value) ) { + return $value; + } + } + + return null; +} |