Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Copyright (c) 2004-2009, Davey Shafik <davey@php.net>
4
 *                          Laurent Laville <pear@laurent-laville.org>
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *     * Redistributions of source code must retain the above copyright
13
 *       notice, this list of conditions and the following disclaimer.
14
 *     * Redistributions in binary form must reproduce the above copyright
15
 *       notice, this list of conditions and the following disclaimer in the
16
 *       documentation and/or other materials provided with the distribution.
17
 *     * Neither the name of the authors nor the names of its contributors
18
 *       may be used to endorse or promote products derived from this software
19
 *       without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
 * POSSIBILITY OF SUCH DAMAGE.
32
 *
33
 * PHP versions 4 and 5
34
 *
35
 * @category PHP
36
 * @package  PHP_CompatInfo
37
 * @author   Davey Shafik <davey@php.net>
38
 * @author   Laurent Laville <pear@laurent-laville.org>
39
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
40
 * @version  CVS: $Id: CompatInfo.php,v 1.108 2009/01/02 10:18:47 farell Exp $
41
 * @link     http://pear.php.net/package/PHP_CompatInfo
42
 * @since    File available since Release 0.7.0
43
 */
44
 
45
require_once 'PHP/CompatInfo/Parser.php';
46
 
47
/**
48
 * Check Compatibility of chunk of PHP code
49
 *
50
 * This class is the controller in the MVC design pattern of API 1.8.0 (since beta 2)
51
 *
52
 * @category  PHP
53
 * @package   PHP_CompatInfo
54
 * @author    Davey Shafik <davey@php.net>
55
 * @author    Laurent Laville <pear@laurent-laville.org>
56
 * @copyright 2003 Davey Shafik and Synaptic Media. All Rights Reserved.
57
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD
58
 * @version   Release: 1.9.0
59
 * @link      http://pear.php.net/package/PHP_CompatInfo
60
 * @since     Class available since Release 0.7.0
61
 */
62
class PHP_CompatInfo
63
{
64
    /**
65
     * Instance of the parser (model in MVC desing pattern)
66
     *
67
     * @var    object
68
     * @since  1.8.0b2
69
     * @access protected
70
     */
71
    var $parser;
72
 
73
    /**
74
     * Class constructor (ZE1) for PHP4
75
     *
76
     * @param string $render (optional) Type of renderer to show results
77
     * @param array  $conf   (optional) A hash containing any additional
78
     *                       configuration a renderer may use
79
     *
80
     * @access public
81
     * @since  version 1.8.0b2 (2008-06-03)
82
     */
83
    function PHP_CompatInfo($render = 'array', $conf = array())
84
    {
85
        $this->__construct($render, $conf);
86
    }
87
 
88
    /**
89
     * Class constructor (ZE2) for PHP5+
90
     *
91
     * @param string $render (optional) Type of renderer to show results
92
     * @param array  $conf   (optional) A hash containing any additional
93
     *                       configuration a renderer may use
94
     *
95
     * @access public
96
     * @since  version 1.8.0b2 (2008-06-03)
97
     */
98
    function __construct($render = 'array', $conf = array())
99
    {
100
        $this->parser = new PHP_CompatInfo_Parser();
101
        $this->parser->setOutputDriver($render, $conf);
102
    }
103
 
104
    /**
105
     * Registers a new listener
106
     *
107
     * Registers a new listener with the given criteria.
108
     *
109
     * @param mixed  $callback A PHP callback
110
     * @param string $nName    (optional) Expected notification name
111
     *
112
     * @access public
113
     * @return void
114
     * @since  version 1.8.0b3 (2008-06-07)
115
     */
116
    function addListener($callback, $nName = EVENT_DISPATCHER_GLOBAL)
117
    {
118
        $this->parser->addListener($callback, $nName);
119
    }
120
 
121
    /**
122
     * Removes a registered listener
123
     *
124
     * Removes a registered listener that correspond to the given criteria.
125
     *
126
     * @param mixed  $callback A PHP callback
127
     * @param string $nName    (optional) Expected notification name
128
     *
129
     * @access public
130
     * @return bool  True if listener was removed, false otherwise.
131
     * @since  version 1.8.0b3 (2008-06-07)
132
     */
133
    function removeListener($callback, $nName = EVENT_DISPATCHER_GLOBAL)
134
    {
135
        return $this->parser->removeListener($callback, $nName);
136
    }
137
 
138
    /**
139
     * Load components list
140
     *
141
     * Load components list for a PHP version or subset
142
     *
143
     * @param string         $min           PHP minimal version
144
     * @param string|boolean $max           (optional) PHP maximal version
145
     * @param boolean        $include_const (optional) include constants list
146
     *                                                 in final result
147
     * @param boolean        $groupby_vers  (optional) give initial php version
148
     *                                                 of function or constant
149
     *
150
     * @return array         An array of php function/constant names history
151
     * @access public
152
     * @static
153
     * @since  version 1.2.0 (2006-08-23)
154
     */
155
    function loadVersion($min, $max = false,
156
                         $include_const = false, $groupby_vers = false)
157
    {
158
        return $this->parser->loadVersion($min, $max, $include_const, $groupby_vers);
159
    }
160
 
161
    /**
162
     * Parse a data source
163
     *
164
     * Parse a data source with auto detect ability. This data source, may be
165
     * one of these follows: a directory, a file, a string (chunk of code),
166
     * an array of multiple origin.
167
     *
168
     * Each of five parsing functions support common and specifics options.
169
     *
170
     *  * Common options :
171
     *  - 'debug'                   Contains a boolean to control whether
172
     *                              extra ouput is shown.
173
     *  - 'ignore_functions'        Contains an array of functions to ignore
174
     *                              when calculating the version needed.
175
     *  - 'ignore_constants'        Contains an array of constants to ignore
176
     *                              when calculating the version needed.
177
     *  - 'ignore_extensions'       Contains an array of php extensions to ignore
178
     *                              when calculating the version needed.
179
     *  - 'ignore_versions'         Contains an array of php versions to ignore
180
     *                              when calculating the version needed.
181
     *  - 'ignore_functions_match'  Contains an array of function patterns to ignore
182
     *                              when calculating the version needed.
183
     *  - 'ignore_extensions_match' Contains an array of extension patterns to ignore
184
     *                              when calculating the version needed.
185
     *  - 'ignore_constants_match'  Contains an array of constant patterns to ignore
186
     *                              when calculating the version needed.
187
     *
188
     *  * parseArray, parseDir|parseFolder, specific options :
189
     *  - 'file_ext'                Contains an array of file extensions to parse
190
     *                              for PHP code. Default: php, php4, inc, phtml
191
     *  - 'ignore_files'            Contains an array of files to ignore.
192
     *                              File names are case insensitive.
193
     *
194
     *  * parseArray specific options :
195
     *  - 'is_string'               Contains a boolean which says if the array values
196
     *                              are strings or file names.
197
     *
198
     *  * parseDir|parseFolder specific options :
199
     *  - 'recurse_dir'             Boolean on whether to recursively find files
200
     *  - 'ignore_dirs'             Contains an array of directories to ignore.
201
     *                              Directory names are case insensitive.
202
     *
203
     * @param mixed $data    Data source (may be file, dir, string, or array)
204
     * @param array $options An array of options. See above.
205
     *
206
     * @access public
207
     * @return array or false on error
208
     * @since  version 1.8.0b2 (2008-06-03)
209
     * @see    PHP_CompatInfo_Parser::parseData()
210
     */
211
    function parseData($data, $options = array())
212
    {
213
        return $this->parser->parseData($data, $options);
214
    }
215
 
216
    /**
217
     * Parse an Array of Files or Strings
218
     *
219
     * You can parse an array of Files or Strings, to parse
220
     * strings, $options['is_string'] must be set to true.
221
     *
222
     * This recommandation is no more valid since version 1.8.0b2
223
     * Array my contains multiple and mixed origin (file, dir, string).
224
     *
225
     * @param array $array   Array of data sources
226
     * @param array $options Parser options (see parseData() method for details)
227
     *
228
     * @access public
229
     * @return array or false on error
230
     * @since  version 0.7.0 (2004-03-09)
231
     * @see    parseData()
232
     */
233
    function parseArray($array, $options = array())
234
    {
235
        return $this->parser->parseData($array, $options);
236
    }
237
 
238
    /**
239
     * Parse a string
240
     *
241
     * Parse a string for its compatibility info
242
     *
243
     * @param string $string  PHP Code to parse
244
     * @param array  $options Parser options (see parseData() method for details)
245
     *
246
     * @access public
247
     * @return array or false on error
248
     * @since  version 0.7.0 (2004-03-09)
249
     * @see    parseData()
250
     */
251
    function parseString($string, $options = array())
252
    {
253
        return $this->parser->parseData($string, $options);
254
    }
255
 
256
    /**
257
     * Parse a single file
258
     *
259
     * Parse a file for its compatibility info
260
     *
261
     * @param string $file    Path of File to parse
262
     * @param array  $options Parser options (see parseData() method for details)
263
     *
264
     * @access public
265
     * @return array or false on error
266
     * @since  version 0.7.0 (2004-03-09)
267
     * @see    parseData()
268
     */
269
    function parseFile($file, $options = array())
270
    {
271
        return $this->parser->parseData($file, $options);
272
    }
273
 
274
    /**
275
     * Parse a directory
276
     *
277
     * Parse a directory recursively for its compatibility info
278
     *
279
     * @param string $dir     Path of folder to parse
280
     * @param array  $options Parser options (see parseData() method for details)
281
     *
282
     * @access public
283
     * @return array or false on error
284
     * @since  version 0.8.0 (2004-04-22)
285
     * @see    parseData()
286
     */
287
    function parseDir($dir, $options = array())
288
    {
289
        return $this->parser->parseData($dir, $options);
290
    }
291
 
292
    /**
293
     * Alias of parseDir
294
     *
295
     * Alias of parseDir function
296
     *
297
     * @param string $folder  Path of folder to parse
298
     * @param array  $options Parser options (see parseData() method for details)
299
     *
300
     * @access public
301
     * @return array or false on error
302
     * @since  version 0.7.0 (2004-03-09)
303
     * @see    parseDir(), parseData()
304
     */
305
    function parseFolder($folder, $options = array())
306
    {
307
        return $this->parser->parseData($folder, $options);
308
    }
309
 
310
    /**
311
     * Returns list of files ignored
312
     *
313
     * Returns list of files ignored while parsing directories
314
     *
315
     * @access public
316
     * @return array or false on error
317
     * @since  version 1.9.0b2 (2008-12-19)
318
     */
319
    function getIgnoredFiles()
320
    {
321
        return $this->parser->getIgnoredFiles();
322
    }
323
 
324
    /**
325
     * Returns the latest parse data source ignored functions
326
     *
327
     * Returns the latest parse data source ignored functions list
328
     *
329
     * @param mixed $file (optional) A specific filename or not (false)
330
     *
331
     * @access public
332
     * @return mixed Null on error or if there were no previous data parsing
333
     * @since  version 1.9.0b2 (2008-12-19)
334
     */
335
    function getIgnoredFunctions($file = false)
336
    {
337
        return $this->parser->getIgnoredFunctions($file);
338
    }
339
 
340
    /**
341
     * Returns the latest parse data source ignored extensions
342
     *
343
     * Returns the latest parse data source ignored extensions list
344
     *
345
     * @param mixed $file (optional) A specific filename or not (false)
346
     *
347
     * @access public
348
     * @return mixed Null on error or if there were no previous data parsing
349
     * @since  version 1.9.0b2 (2008-12-19)
350
     */
351
    function getIgnoredExtensions($file = false)
352
    {
353
        return $this->parser->getIgnoredExtensions($file);
354
    }
355
 
356
    /**
357
     * Returns the latest parse data source ignored constants
358
     *
359
     * Returns the latest parse data source ignored constants list
360
     *
361
     * @param mixed $file (optional) A specific filename or not (false)
362
     *
363
     * @access public
364
     * @return mixed Null on error or if there were no previous data parsing
365
     * @since  version 1.9.0b2 (2008-12-19)
366
     */
367
    function getIgnoredConstants($file = false)
368
    {
369
        return $this->parser->getIgnoredConstants($file);
370
    }
371
 
372
    /**
373
     * Returns the latest parse data source version
374
     *
375
     * Returns the latest parse data source version, minimum and/or maximum
376
     *
377
     * @param mixed $file (optional) A specific filename or not (false)
378
     * @param bool  $max  (optional) Level with or without contextual data
379
     *
380
     * @access public
381
     * @return mixed Null on error or if there were no previous data parsing
382
     * @since  version 1.9.0b1 (2008-11-30)
383
     */
384
    function getVersion($file = false, $max = false)
385
    {
386
        return $this->parser->getVersion($file, $max);
387
    }
388
 
389
    /**
390
     * Returns the latest parse data source classes declared
391
     *
392
     * Returns the latest parse data source classes declared (internal or
393
     * end-user defined)
394
     *
395
     * @param mixed $file (optional) A specific filename or not (false)
396
     *
397
     * @access public
398
     * @return mixed Null on error or if there were no previous data parsing
399
     * @since  version 1.9.0b1 (2008-11-30)
400
     */
401
    function getClasses($file = false)
402
    {
403
        return $this->parser->getClasses($file);
404
    }
405
 
406
    /**
407
     * Returns the latest parse data source functions declared
408
     *
409
     * Returns the latest parse data source functions declared (internal or
410
     * end-user defined)
411
     *
412
     * @param mixed $file (optional) A specific filename or not (false)
413
     *
414
     * @access public
415
     * @return mixed Null on error or if there were no previous data parsing
416
     * @since  version 1.9.0b1 (2008-11-30)
417
     */
418
    function getFunctions($file = false)
419
    {
420
        return $this->parser->getFunctions($file);
421
    }
422
 
423
    /**
424
     * Returns the latest parse data source extensions used
425
     *
426
     * Returns the latest parse data source extensions used
427
     *
428
     * @param mixed $file (optional) A specific filename or not (false)
429
     *
430
     * @access public
431
     * @return mixed Null on error or if there were no previous data parsing
432
     * @since  version 1.9.0b1 (2008-11-30)
433
     */
434
    function getExtensions($file = false)
435
    {
436
        return $this->parser->getExtensions($file);
437
    }
438
 
439
    /**
440
     * Returns the latest parse data source constants declared
441
     *
442
     * Returns the latest parse data source constants declared (internal or
443
     * end-user defined)
444
     *
445
     * @param mixed $file (optional) A specific filename or not (false)
446
     *
447
     * @access public
448
     * @return mixed Null on error or if there were no previous data parsing
449
     * @since  version 1.9.0b1 (2008-11-30)
450
     */
451
    function getConstants($file = false)
452
    {
453
        return $this->parser->getConstants($file);
454
    }
455
 
456
    /**
457
     * Returns the latest parse data source tokens declared
458
     *
459
     * Returns the latest parse data source PHP5+ tokens declared
460
     *
461
     * @param mixed $file (optional) A specific filename or not (false)
462
     *
463
     * @access public
464
     * @return mixed Null on error or if there were no previous data parsing
465
     * @since  version 1.9.0b1 (2008-11-30)
466
     */
467
    function getTokens($file = false)
468
    {
469
        return $this->parser->getTokens($file);
470
    }
471
 
472
    /**
473
     * Returns the latest parse data source conditions
474
     *
475
     * Returns the latest parse data source conditions, with or without
476
     * contextual data
477
     *
478
     * @param mixed $file      (optional) A specific filename or not (false)
479
     * @param bool  $levelOnly (optional) Level with or without contextual data
480
     *
481
     * @access public
482
     * @return mixed Null on error or if there were no previous data parsing
483
     * @since  version 1.9.0b1 (2008-11-30)
484
     */
485
    function getConditions($file = false, $levelOnly = false)
486
    {
487
        return $this->parser->getConditions($file, $levelOnly);
488
    }
489
 
490
    /**
491
     * Returns the summary of parsing info
492
     *
493
     * Returns only summary when parsing a directory or multiple data sources
494
     *
495
     * @access public
496
     * @return array
497
     * @since  version 1.9.0 (2009-01-19)
498
     */
499
    function getSummary()
500
    {
501
        $summary = array('ignored_files'      => $this->getIgnoredFiles(),
502
                         'ignored_functions'  => $this->getIgnoredFunctions(),
503
                         'ignored_extensions' => $this->getIgnoredExtensions(),
504
                         'ignored_constants'  => $this->getIgnoredConstants(),
505
                         'max_version'        => $this->getVersion(false, true),
506
                         'version'            => $this->getVersion(),
507
                         'classes'            => $this->getClasses(),
508
                         'functions'          => $this->getFunctions(),
509
                         'extensions'         => $this->getExtensions(),
510
                         'constants'          => $this->getConstants(),
511
                         'tokens'             => $this->getTokens(),
512
                         'cond_code'          => $this->getConditions()
513
                         );
514
        if ($this->parser->options['debug'] == false) {
515
            unset($summary['functions']);
516
        }
517
        return $summary;
518
    }
519
}
520
?>