/var/www/hkosl.com/nick/codeigniter/application/vendor/phpunit/phpunit/src/Util/GlobalState.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

class PHPUnit_Util_GlobalState
{
    
/**
     * @var array
     */
    
protected static $superGlobalArrays = [
      
'_ENV',
      
'_POST',
      
'_GET',
      
'_COOKIE',
      
'_SERVER',
      
'_FILES',
      
'_REQUEST'
    
];

    
/**
     * @var array
     */
    
protected static $superGlobalArraysLong = [
      
'HTTP_ENV_VARS',
      
'HTTP_POST_VARS',
      
'HTTP_GET_VARS',
      
'HTTP_COOKIE_VARS',
      
'HTTP_SERVER_VARS',
      
'HTTP_POST_FILES'
    
];

    
/**
     * @return string
     */
    
public static function getIncludedFilesAsString()
    {
        return static::
processIncludedFilesAsString(get_included_files());
    }

    
/**
     * @param array $files
     *
     * @return string
     */
    
public static function processIncludedFilesAsString(array $files)
    {
        
$blacklist = new PHPUnit_Util_Blacklist;
        
$prefix    false;
        
$result    '';

        if (
defined('__PHPUNIT_PHAR__')) {
            
$prefix 'phar://' __PHPUNIT_PHAR__ '/';
        }

        for (
$i count($files) - 1$i 0$i--) {
            
$file $files[$i];

            if (
$prefix !== false && strpos($file$prefix) === 0) {
                continue;
            }

            
// Skip virtual file system protocols
            
if (preg_match('/^(vfs|phpvfs[a-z0-9]+):/'$file)) {
                continue;
            }

            if (!
$blacklist->isBlacklisted($file) && is_file($file)) {
                
$result 'require_once \'' $file "';\n" $result;
            }
        }

        return 
$result;
    }

    
/**
     * @return string
     */
    
public static function getIniSettingsAsString()
    {
        
$result      '';
        
$iniSettings ini_get_all(nullfalse);

        foreach (
$iniSettings as $key => $value) {
            
$result .= sprintf(
                
'@ini_set(%s, %s);' "\n",
                
self::exportVariable($key),
                
self::exportVariable($value)
            );
        }

        return 
$result;
    }

    
/**
     * @return string
     */
    
public static function getConstantsAsString()
    {
        
$constants get_defined_constants(true);
        
$result    '';

        if (isset(
$constants['user'])) {
            foreach (
$constants['user'] as $name => $value) {
                
$result .= sprintf(
                    
'if (!defined(\'%s\')) define(\'%s\', %s);' "\n",
                    
$name,
                    
$name,
                    
self::exportVariable($value)
                );
            }
        }

        return 
$result;
    }

    
/**
     * @return string
     */
    
public static function getGlobalsAsString()
    {
        
$result            '';
        
$superGlobalArrays self::getSuperGlobalArrays();

        foreach (
$superGlobalArrays as $superGlobalArray) {
            if (isset(
$GLOBALS[$superGlobalArray]) &&
                
is_array($GLOBALS[$superGlobalArray])) {
                foreach (
array_keys($GLOBALS[$superGlobalArray]) as $key) {
                    if (
$GLOBALS[$superGlobalArray][$key] instanceof Closure) {
                        continue;
                    }

                    
$result .= sprintf(
                        
'$GLOBALS[\'%s\'][\'%s\'] = %s;' "\n",
                        
$superGlobalArray,
                        
$key,
                        
self::exportVariable($GLOBALS[$superGlobalArray][$key])
                    );
                }
            }
        }

        
$blacklist   $superGlobalArrays;
        
$blacklist[] = 'GLOBALS';

        foreach (
array_keys($GLOBALS) as $key) {
            if (!
in_array($key$blacklist) && !$GLOBALS[$key] instanceof Closure) {
                
$result .= sprintf(
                    
'$GLOBALS[\'%s\'] = %s;' "\n",
                    
$key,
                    
self::exportVariable($GLOBALS[$key])
                );
            }
        }

        return 
$result;
    }

    
/**
     * @return array
     */
    
protected static function getSuperGlobalArrays()
    {
        if (
ini_get('register_long_arrays') == '1') {
            return 
array_merge(
                
self::$superGlobalArrays,
                
self::$superGlobalArraysLong
            
);
        } else {
            return 
self::$superGlobalArrays;
        }
    }

    protected static function 
exportVariable($variable)
    {
        if (
is_scalar($variable) || is_null($variable) ||
           (
is_array($variable) && self::arrayOnlyContainsScalars($variable))) {
            return 
var_export($variabletrue);
        }

        return 
'unserialize(' .
                
var_export(serialize($variable), true) .
                
')';
    }

    
/**
     * @param array $array
     *
     * @return bool
     */
    
protected static function arrayOnlyContainsScalars(array $array)
    {
        
$result true;

        foreach (
$array as $element) {
            if (
is_array($element)) {
                
$result self::arrayOnlyContainsScalars($element);
            } elseif (!
is_scalar($element) && !is_null($element)) {
                
$result false;
            }

            if (
$result === false) {
                break;
            }
        }

        return 
$result;
    }
}