Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • BigDecimal
  • BigInt
  • ByteStream
  • LocalDate
  • Location
  • Money
  • Name
  • Point
  • S3
  • Timestamp
  • Utils
  • UUID
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace NGS;
 3: 
 4: /**
 5:  * Some helper methods
 6:  */
 7: abstract class Utils
 8: {
 9:     private static $warningsAsErrors;
10: 
11:     /**
12:      * Returns type of variable, as in native gettype, or name of class if $var
13:      * is of 'object' or 'resource' type
14:      * @param mixed $var
15:      * @return string Type of variable
16:      */
17:     public static function getType($var)
18:     {
19:         // native gettype
20:         $type = \gettype($var);
21: 
22:         if($type === 'object')
23:             return get_class($var);
24:         if($type === 'resource')
25:             return get_resource_type($var);
26:         return $type;
27:     }
28: 
29:     /**
30:      * Controls whether certain warnings are thrown as exceptions (default)
31:      * If set to false, warnings are ignored
32:      * @param bool $wae True/false to turn on/off, null to get current value
33:      * @return bool If null is given
34:      */
35:     public static function WarningsAsErrors($wae = null)
36:     {
37:         if($wae === null)
38:             return self::$warningsAsErrors;
39:         self::$warningsAsErrors = (bool)$wae;
40:     }
41: 
42:     /**
43:      * Checks if json string is a json array
44:      * (only checks if  a string starts with a '[')
45:      * @param string $json A valid json string
46:      * @return bool
47:      */
48:     public static function isJsonArray($json)
49:     {
50:         return ord(ltrim($json)) === 91;
51:     }
52: 
53:     /**
54:      * Calls __toString on every member of given object array
55:      * @param array $list Array of objects
56:      * @return array Array of string values
57:      */
58:     public static function toStringArray(array $list)
59:     {
60:         $res = array();
61: 
62:         foreach ($list as $key => $val) {
63:             $res[$key] = $val !== null ? $val->__toString() : null;
64:         }
65: 
66:         return $res;
67:     }
68: }
69: 
API documentation generated by ApiGen 2.8.0