RSI helpers  0.1
RSI helpers
Rsi.php
Go to the documentation of this file.
1 <?php
2 
3 class Rsi{
4 
5  /**
6  * Check if PHP is run from the command line.
7  * @return bool
8  */
9  public static function commandLine(){
10  return PHP_SAPI == 'cli';
11  }
12  /**
13  * Check wether we are running on a Windows machine.
14  * @return bool
15  */
16  public static function windows(){
17  return strncasecmp(PHP_OS,'Win',3) == 0;
18  }
19  /**
20  * Simple command line argument parser.
21  * Supports values of form key=value (value is true when omitted). When the same key is encountered multiple times an array
22  * will be returned.
23  * @return array Assoc.array with the key=value pairs from the command line arguments.
24  */
25  public static function parseArgs(){
26  global $argc,$argv;
27 
28  $args = [];
29  for($i = 1; $i < $argc; $i++){
30  list($key,$value) = array_merge(explode('=',$argv[$i],2),[true]);
31  if(array_key_exists($key,$args)){
32  if(!is_array($args[$key])) $args[$key] = [$args[$key]];
33  $args[$key][] = $value;
34  }
35  else $args[$key] = $value;
36  }
37  return $args;
38  }
39  /**
40  * Check PHP version.
41  * @param string $version Version to compare to.
42  * @return bool True if the current PHP-version is greater or equal than the provided version.
43  */
44  public static function version($version){
45  return version_compare(PHP_VERSION,$version,'>=');
46  }
47  /**
48  * Script memory limit.
49  * @return int Maximum number of bytes.
50  */
51  public static function memoryLimit(){
52  return \Rsi\Number::shorthandBytes(ini_get('memory_limit'));
53  }
54  /**
55  * Check if a value is empty.
56  * @param mixed $value
57  * @return bool True when empty.
58  */
59  public static function nothing($value){
60  return is_array($value) ? !$value : !strlen($value);
61  }
62 
63 }
static version($version)
Check PHP version.
Definition: Rsi.php:44
static nothing($value)
Check if a value is empty.
Definition: Rsi.php:59
static commandLine()
Check if PHP is run from the command line.
Definition: Rsi.php:9
static windows()
Check wether we are running on a Windows machine.
Definition: Rsi.php:16
static memoryLimit()
Script memory limit.
Definition: Rsi.php:51
Definition: Color.php:3
static parseArgs()
Simple command line argument parser.
Definition: Rsi.php:25