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) 2008-2009, Laurent Laville <pear@laurent-laville.org>
4
 *
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *     * Redistributions of source code must retain the above copyright
12
 *       notice, this list of conditions and the following disclaimer.
13
 *     * Redistributions in binary form must reproduce the above copyright
14
 *       notice, this list of conditions and the following disclaimer in the
15
 *       documentation and/or other materials provided with the distribution.
16
 *     * Neither the name of the authors nor the names of its contributors
17
 *       may be used to endorse or promote products derived from this software
18
 *       without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGE.
31
 *
32
 * PHP versions 4 and 5
33
 *
34
 * @category PHP
35
 * @package  PHP_CompatInfo
36
 * @author   Laurent Laville <pear@laurent-laville.org>
37
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
38
 * @version  CVS: $Id: Csv.php,v 1.6 2009/01/02 10:18:47 farell Exp $
39
 * @link     http://pear.php.net/package/PHP_CompatInfo
40
 * @since    File available since Release 1.8.0b3
41
 */
42
 
43
/**
44
 * Csv renderer for PHP_CompatInfo component.
45
 *
46
 * The PHP_CompatInfo_Renderer_Csv class is a concrete implementation
47
 * of PHP_CompatInfo_Renderer abstract class. It simply output informations
48
 * in Comma Seperated Value style.
49
 *
50
 * @category PHP
51
 * @package  PHP_CompatInfo
52
 * @author   Laurent Laville <pear@laurent-laville.org>
53
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
54
 * @version  Release: 1.9.0
55
 * @link     http://pear.php.net/package/PHP_CompatInfo
56
 * @since    Class available since Release 1.8.0b4
57
 */
58
class PHP_CompatInfo_Renderer_Csv extends PHP_CompatInfo_Renderer
59
{
60
    /**
61
     * Csv Renderer Class constructor (ZE1) for PHP4
62
     *
63
     * @param object &$parser Instance of the parser (model of MVC pattern)
64
     * @param array  $conf    A hash containing any additional configuration
65
     *
66
     * @access public
67
     * @since  version 1.8.0b4 (2008-06-18)
68
     */
69
    function PHP_CompatInfo_Renderer_Csv(&$parser, $conf)
70
    {
71
        $this->__construct($parser, $conf);
72
    }
73
 
74
    /**
75
     * Csv Renderer Class constructor (ZE2) for PHP5+
76
     *
77
     * @param object &$parser Instance of the parser (model of MVC pattern)
78
     * @param array  $conf    A hash containing any additional configuration
79
     *
80
     * @access public
81
     * @since  version 1.8.0b4 (2008-06-18)
82
     */
83
    function __construct(&$parser, $conf)
84
    {
85
        $defaults = array('fields-values-separated-by' => ',',
86
                          'fields-terminated-by' => ';',
87
                          'fields-enclosed-by' => '"',
88
                          'lines-terminated-by' => PHP_EOL);
89
        $conf     = array_merge($defaults, $conf);
90
 
91
        parent::PHP_CompatInfo_Renderer($parser, $conf);
92
    }
93
 
94
    /**
95
     * Display final results
96
     *
97
     * Display final results, when data source parsing is over.
98
     *
99
     * @access public
100
     * @return void
101
     * @since  version 1.8.0b4 (2008-06-18)
102
     */
103
    function display()
104
    {
105
        $fvsb = $this->conf['fields-values-separated-by'];
106
        $o    = $this->args['output-level'];
107
        $info = $this->parseData;
108
        $hdr  = array();
109
        $src  = $this->_parser->dataSource;
110
 
111
        if ($info === false) {
112
            // invalid data source
113
            return;
114
        }
115
 
116
        $options = $this->_parser->options;
117
 
118
        if (isset($this->args['dir'])) {
119
            $dir   = $this->args['dir'];
120
            $hdr[] = 'Files';
121
        } elseif (isset($this->args['file'])) {
122
            $file  = $this->args['file'];
123
            $hdr[] = 'File';
124
        } elseif (isset($this->args['string'])) {
125
            $string = $this->args['string'];
126
            $hdr[]  = 'Source code';
127
        } elseif ($src['dataType'] == 'directory') {
128
            $dir   = $src['dataSource'];
129
            $hdr[] = 'Files';
130
        } elseif ($src['dataType'] == 'file') {
131
            $file  = $src['dataSource'];
132
            $hdr[] = 'File';
133
        } else {
134
            if ($options['is_string'] == true) {
135
                $string = $src['dataSource'];
136
                $hdr[]  = 'Source code';
137
            } else {
138
                $dir   = $src['dataSource'];
139
                $hdr[] = 'Files';
140
            }
141
        }
142
 
143
        if ($o & 16) {
144
            $hdr[] = 'Version';
145
        }
146
        if ($o & 1) {
147
            $hdr[] = 'C';
148
        }
149
        if ($o & 2) {
150
            $hdr[] = 'Extensions';
151
        }
152
        if ($o & 4) {
153
            if ($o & 8) {
154
                $hdr[] = 'Constants/Tokens';
155
            } else {
156
                $hdr[] = 'Constants';
157
            }
158
        } else {
159
            if ($o & 8) {
160
                $hdr[] = 'Tokens';
161
            }
162
        }
163
        // print headers
164
        $this->_printf($hdr);
165
 
166
        $ext   = implode($fvsb, $info['extensions']);
167
        $const = implode($fvsb, array_merge($info['constants'], $info['tokens']));
168
        if (isset($dir)) {
169
            $ds = DIRECTORY_SEPARATOR;
170
            if (is_array($dir)) {
171
                $data = array(dirname($dir[0]));
172
            } else {
173
                $dir  = str_replace(array('\\', '/'), $ds, $dir);
174
                $data = array($dir);
175
            }
176
        } elseif (isset($file)) {
177
            $data = array($file);
178
        } else {
179
            $data = array('<?php ... ?>');
180
        }
181
 
182
        if ($o & 16) {
183
            if (empty($info['max_version'])) {
184
                $data[] = $info['version'];
185
            } else {
186
                $data[] = implode($fvsb, array($info['version'],
187
                                               $info['max_version']));
188
            }
189
        }
190
        if ($o & 1) {
191
            $data[] = $info['cond_code'][0];
192
        }
193
        if ($o & 2) {
194
            $data[] = $ext;
195
        }
196
        if ($o & 4) {
197
            if ($o & 8) {
198
                $data[] = $const;
199
            } else {
200
                $data[] = implode($fvsb, $info['constants']);
201
            }
202
        } else {
203
            if ($o & 8) {
204
                $data[] = implode($fvsb, $info['tokens']);
205
            }
206
        }
207
 
208
        $this->_printf($data);
209
 
210
        // summarize : print only summary for directory without files details
211
        if ($this->args['summarize'] === false && isset($dir)) {
212
 
213
            unset($info['max_version']);
214
            unset($info['version']);
215
            unset($info['classes']);
216
            unset($info['functions']);
217
            unset($info['extensions']);
218
            unset($info['constants']);
219
            unset($info['tokens']);
220
            unset($info['cond_code']);
221
 
222
            $ignored = $info['ignored_files'];
223
 
224
            unset($info['ignored_files']);
225
            unset($info['ignored_functions']);
226
            unset($info['ignored_extensions']);
227
            unset($info['ignored_constants']);
228
 
229
            foreach ($info as $file => $info) {
230
                if ($info === false) {
231
                    continue;  // skip this (invalid) file
232
                }
233
                $ext   = implode($fvsb, $info['extensions']);
234
                $const = implode($fvsb, array_merge($info['constants'],
235
                                                    $info['tokens']));
236
 
237
                $file = str_replace(array('\\', '/'), $ds, $file);
238
 
239
                $data = array($file);
240
                if ($o & 16) {
241
                    if (empty($info['max_version'])) {
242
                        $data[] = $info['version'];
243
                    } else {
244
                        $data[] = implode($fvsb, array($info['version'],
245
                                                       $info['max_version']));
246
                    }
247
                }
248
                if ($o & 1) {
249
                    $data[] = $info['cond_code'][0];
250
                }
251
                if ($o & 2) {
252
                    $data[] = $ext;
253
                }
254
                if ($o & 4) {
255
                    if ($o & 8) {
256
                        $data[] = $const;
257
                    } else {
258
                        $data[] = implode($fvsb, $info['constants']);
259
                    }
260
                } else {
261
                    if ($o & 8) {
262
                        $data[] = implode($fvsb, $info['tokens']);
263
                    }
264
                }
265
 
266
                $this->_printf($data);
267
            }
268
        }
269
    }
270
 
271
    /**
272
     * Print a single line of CSV report
273
     *
274
     * @param array $data Data list to print
275
     *
276
     * @return void
277
     * @access private
278
     * @since  1.8.0b4 (2008-06-18)
279
     */
280
    function _printf($data)
281
    {
282
        $string = '';
283
 
284
        foreach ($data as $i => $d) {
285
            if ($i > 0) {
286
                $string .= $this->conf['fields-terminated-by'];
287
            }
288
            $string .= $this->conf['fields-enclosed-by'] . $d .
289
                       $this->conf['fields-enclosed-by'];
290
        }
291
        $string .= $this->conf['lines-terminated-by'];
292
 
293
        echo $string;
294
    }
295
}
296
?>