Version 1
[yaffs-website] / web / modules / contrib / devel / kint / kint / inc / kintVariableData.class.php
1 <?php
2
3 class kintVariableData
4 {
5         /** @var string */
6         public $type;
7         /** @var string */
8         public $access;
9         /** @var string */
10         public $name;
11         /** @var string */
12         public $operator;
13         /** @var int */
14         public $size;
15         /**
16          * @var kintVariableData[] array of kintVariableData objects or strings; displayed collapsed, each element from
17          * the array is a separate possible representation of the dumped var
18          */
19         public $extendedValue;
20         /** @var string inline value */
21         public $value;
22
23         /** @var kintVariableData[] array of alternative representations for same variable, don't use in custom parsers */
24         public $_alternatives;
25
26         /* *******************************************
27          * HELPERS
28          */
29
30         private static $_supportedCharsets = array(
31                 'UTF-8',
32                 'Windows-1252', # Western; includes iso-8859-1
33                 'euc-jp',       # Japanese
34
35                 # all other charsets cannot be differentiated by PHP and/or are not supported by mb_* functions,
36                 # I need a better means of detecting the codeset, no idea how though :(
37
38                 //              'iso-8859-13',  # Baltic
39                 //              'windows-1251', # Cyrillic
40                 //              'windows-1250', # Central European
41                 //              'shift_jis',    # Japanese
42                 //              'iso-2022-jp',  # Japanese
43         );
44
45         protected static function _detectEncoding( $value )
46         {
47                 $ret = null;
48                 if ( function_exists( 'mb_detect_encoding' ) ) {
49                         $mbDetected = mb_detect_encoding( $value );
50                         if ( $mbDetected === 'ASCII' ) return 'ASCII';
51                 }
52
53
54                 if ( !function_exists( 'iconv' ) ) {
55                         return !empty( $mbDetected ) ? $mbDetected : 'UTF-8';
56                 }
57
58                 $md5 = md5( $value );
59                 foreach ( Kint::$charEncodings as $encoding ) {
60                         # fuck knows why, //IGNORE and //TRANSLIT still throw notice
61                         if ( md5( @iconv( $encoding, $encoding, $value ) ) === $md5 ) {
62                                 return $encoding;
63                         }
64                 }
65
66                 return 'ASCII';
67         }
68
69         /**
70          * returns whether the array:
71          *  1) is numeric and
72          *  2) in sequence starting from zero
73          *
74          * @param array $array
75          *
76          * @return bool
77          */
78         protected static function _isSequential( array $array )
79         {
80                 return array_keys( $array ) === range( 0, count( $array ) - 1 );
81         }
82
83         protected static function _strlen( $string, $encoding = null )
84         {
85                 if ( function_exists( 'mb_strlen' ) ) {
86                         $encoding or $encoding = self::_detectEncoding( $string );
87                         return mb_strlen( $string, $encoding );
88                 } else {
89                         return strlen( $string );
90                 }
91         }
92
93         protected static function _substr( $string, $start, $end, $encoding = null )
94         {
95                 if ( function_exists( 'mb_substr' ) ) {
96                         $encoding or $encoding = self::_detectEncoding( $string );
97                         return mb_substr( $string, $start, $end, $encoding );
98                 } else {
99                         return substr( $string, $start, $end );
100                 }
101         }
102 }