C:\xampp\php\CompatInfo\Renderer.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<?php
/**
 * Copyright (c) 2008-2009, Laurent Laville <pear@laurent-laville.org>
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the authors nor the names of its contributors
 *       may be used to endorse or promote products derived from this software
 *       without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * PHP versions 4 and 5
 *
 * @category PHP
 * @package  PHP_CompatInfo
 * @author   Laurent Laville <pear@laurent-laville.org>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
 * @version  CVS: $Id: Renderer.php,v 1.9 2009/01/02 10:18:47 farell Exp $
 * @link     http://pear.php.net/package/PHP_CompatInfo
 * @since    File available since Release 1.8.0b2
 */

/**
 * Base class used by all renderers
 *
 * @category PHP
 * @package  PHP_CompatInfo
 * @author   Laurent Laville <pear@laurent-laville.org>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
 * @version  Release: 1.9.0
 * @link     http://pear.php.net/package/PHP_CompatInfo
 * @since    Class available since Release 1.8.0b2
 * @abstract
 */
class PHP_CompatInfo_Renderer
{
    
/**
     * PHP_CompatInfo_Parser instance
     *
     * @var    object
     * @access private
     */
    
var $_parser;

    
/**
     * @var    mixed    Progress bar render options (available only on CLI sapi)
     * @since  1.8.0b1
     * @access private
     */
    
var $_pbar;

    
/**
     * @var    string   End of line string (depending of server API)
     * @access public
     */
    
var $eol;

    
/**
     * Silent mode. Display or not extra info messages.
     *
     * @var    boolean
     * @access public
     */
    
var $silent;

    
/**
     * Data source parsed final results
     *
     * @var    array
     * @access public
     */
    
var $parseData;

    
/**
     * All console arguments that have been parsed and recognized
     *
     * @var   array
     * @since 1.8.0RC1
     * @access public
     */
    
var $args;

    
/**
     * A hash containing any additional configuration of specific driver
     *
     * @var    array
     * @since  1.8.0RC1
     * @access public
     */
    
var $conf;

    
/**
     * Base Renderer Class constructor
     *
     * Base Renderer Class constructor (ZE1) for PHP4
     *
     * @param object &$parser Instance of the parser (model of MVC pattern)
     * @param array  $conf    A hash containing any additional configuration
     *
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function PHP_CompatInfo_Renderer(&$parser$conf)
    {
        
PHP_CompatInfo_Renderer::__construct($parser$conf);
    }

    
/**
     * Base Renderer Class constructor
     *
     * Base Renderer Class constructor (ZE2) for PHP5+
     *
     * @param object &$parser Instance of the parser (model of MVC pattern)
     * @param array  $conf    A hash containing any additional configuration
     *
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function __construct(&$parser$conf)
    {
        
$this->_parser $parser;

        
$args = array(
            
'summarize' => false,
            
'output-level' => 31,
            
'verbose' => 0
            
);
        if (isset(
$conf['args']) && is_array($conf['args'])) {
            
$this->args array_merge($args$conf['args']);
            unset(
$conf['args']);
        } else {
            
$this->args $args;
        }
        
$this->conf $conf;

        if (
php_sapi_name() == 'cli') {
            
// when running the CLI version, take arguments from console
            
if (isset($this->args['progress'])) {
                
$conf['progress'] = $this->args['progress'];
                
$conf['silent']   = false;
            }
            
$this->eol PHP_EOL;
        } else {
            
$this->eol '<br/>'PHP_EOL;
        }

        
// activate (or not) the silent mode
        
if (!isset($conf['silent'])) {
            
$this->silent true;  // default behavior
        
} else {
            
$this->silent = (bool) $conf['silent'];
        }

        if (isset(
$conf['progress']) && $conf['progress'] == 'bar') {
            
// wait style = progress bar prefered (if available)
            
$progressBar 'Console/ProgressBar.php';
            if (
php_sapi_name() == 'cli'
                
&& PHP_CompatInfo_Renderer::isIncludable($progressBar)) {

                include_once 
$progressBar;

                
// default progress bar render options
                
$default = array('formatString' => '- %fraction% files' .
                                                   
' [%bar%] %percent%' .
                                                   
' Elapsed Time: %elapsed%',
                                 
'barfill' => '=>',
                                 
'prefill' => '-',
                                 
'options' => array());

                
// apply custom render options if given
                
if (isset($conf['progressbar'])) {
                    
$pbar $conf['progressbar'];
                } else {
                    
$pbar = array();
                }
                
$this->_pbar array_merge($default$pbar);
            } else {
                
// no progress bar available
                
$this->_pbar false;
            }
        } else {
            
// wait style = text prefered
            
$this->_pbar false;
        }

        
// register the compatInfo view as observer
        
$parser->addListener(array(&$this'update'));
    }

    
/**
     * Create required instance of the Output 'driver'.
     *
     * Creates a concrete instance of the renderer depending of $type
     *
     * @param object &$parser A concrete instance of the parser
     * @param string $type    (optional) Type of instance required, case insensitive
     * @param array  $conf    (optional) A hash containing any additional
     *                        configuration information that a subclass might need.
     *
     * @return object PHP_CompatInfo_Renderer A concrete PHP_CompatInfo_Renderer
     *                                        instance, or null on error.
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function &factory(&$parser$type 'array'$conf = array())
    {
        
$class 'PHP_CompatInfo_Renderer_' ucfirst(strtolower($type));
        
$file  str_replace('_''/'$class) . '.php';

        
/**
         * Attempt to include our version of the named class, but don't treat
         * a failure as fatal.  The caller may have already included their own
         * version of the named class.
         */
        
if (!PHP_CompatInfo_Renderer::_classExists($class)) {
            include_once 
$file;
        }

        
// If the class exists, return a new instance of it.
        
if (PHP_CompatInfo_Renderer::_classExists($class)) {
            
$instance =& new $class($parser$conf);
        } else {
            
$instance null;
        }

        return 
$instance;
    }

    
/**
     * Update the current view
     *
     * Interface to update the view with current information.
     * Listen events produced by Event_Dispatcher and the PHP_CompatInfo_Parser
     *
     * @param object &$auditEvent Instance of Event_Dispatcher
     *
     * @return void
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function update(&$auditEvent)
    {
        
$notifyName $auditEvent->getNotificationName();
        
$notifyInfo $auditEvent->getNotificationInfo();

        switch (
$notifyName) {
        case 
PHP_COMPATINFO_EVENT_AUDITSTARTED :
            
$this->startWaitProgress($notifyInfo['dataCount']);
            break;
        case 
PHP_COMPATINFO_EVENT_AUDITFINISHED :
            if (!isset(
$this->parseData)) {
                
// invalid data source
                
$this->parseData false;
            }
            
$this->endWaitProgress();
            
$this->display();
            break;
        case 
PHP_COMPATINFO_EVENT_FILESTARTED :
            
$this->stillWaitProgress($notifyInfo['filename'],
                                     
$notifyInfo['fileindex']);
            break;
        case 
PHP_COMPATINFO_EVENT_CODESTARTED :
            
$this->stillWaitProgress($notifyInfo['stringdata'],
                                     
$notifyInfo['stringindex']);
            break;
        case 
PHP_COMPATINFO_EVENT_FILEFINISHED :
        case 
PHP_COMPATINFO_EVENT_CODEFINISHED :
            
$this->parseData $notifyInfo;
            break;
        }
    }

    
/**
     * Initialize the wait process
     *
     * Initialize the wait process, with a simple message or a progress bar.
     *
     * @param integer $maxEntries Number of source to parse
     *
     * @return void
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function startWaitProgress($maxEntries)
    {
        if (
$this->silent == false) {
            
// obey at silent mode protocol
            
if ($maxEntries == 0) {
                
// protect against invalid data source
                
$this->_pbar false;
            }
            if (
$this->_pbar) {
                
$this->_pbar = new Console_ProgressBar($this->_pbar['formatString'],
                                               
$this->_pbar['barfill'],
                                               
$this->_pbar['prefill'],
                                               
78,
                                               
$maxEntries,
                                               
$this->_pbar['options']);
            } else {
                echo 
'Wait while parsing data source ...'
                   
$this->eol;
            }
        }
    }

    
/**
     * Update the wait message
     *
     * Update the wait message, or status of the progress bar
     *
     * @param string $source Source (file, string) currently parsing
     * @param string $index  Position of the $source in the data source list
     *                       to parse
     *
     * @return void
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function stillWaitProgress($source$index)
    {
        if (
$this->silent == false) {
            
// obey at silent mode protocol
            
if ($this->_pbar) {
                
// update the progress bar
                
$this->_pbar->update($index);
            } else {
                if (
is_file($source)) {
                    echo 
'Wait while parsing file "' $source '"'
                       
$this->eol;
                } else {
                    echo 
'Wait while parsing string "' $index '"'
                       
$this->eol;
                }
            }
        }
    }

    
/**
     * Finish the wait process
     *
     * Finish the wait process, by erasing the progress bar
     *
     * @return void
     * @access public
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function endWaitProgress()
    {
        if (
$this->silent == false) {
            
// obey at silent mode protocol
            
if ($this->_pbar) {
                
// remove the progress bar
                
$this->_pbar->erase(true);
            }
        }
    }

    
/**
     * Checks if in the include path
     *
     * Returns whether or not a file is in the include path
     *
     * @param string $file Path to filename to check if includable
     *
     * @static
     * @access public
     * @return boolean True if the file is in the include path, false otherwise
     * @since  version 1.7.0b4 (2008-04-03)
     */
    
function isIncludable($file)
    {
        foreach (
explode(PATH_SEPARATORget_include_path()) as $ip) {
            if (
file_exists($ip DIRECTORY_SEPARATOR $file)
                && 
is_readable($ip DIRECTORY_SEPARATOR $file)
                ) {
                return 
true;
            }
        }
        return 
false;
    }

    
/**
     * Utility function which wraps PHP's class_exists() function to ensure
     * consistent behavior between PHP versions 4 and 5. Autoloading behavior
     * is always disabled.
     *
     * @param string $class The name of the class whose existence should be tested.
     *
     * @return bool         True if the class exists, false otherwiser.
     *
     * @static
     * @access private
     * @since  version 1.8.0b2 (2008-06-03)
     */
    
function _classExists($class)
    {
        if (
version_compare(PHP_VERSION'5.0.0''ge')) {
            return 
class_exists($classfalse);
        }

        return 
class_exists($class);
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586