summaryrefslogtreecommitdiff
path: root/buildscripts/PhpDocumentor/phpDocumentor/ParserData.inc
blob: d7d0f2854199821dfe07aa61f026315eab02328d (plain)
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
<?php
//
// +------------------------------------------------------------------------+
// | phpDocumentor                                                          |
// +------------------------------------------------------------------------+
// | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
// | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
// | Web           http://www.phpdoc.org                                    |
// | Mirror        http://phpdocu.sourceforge.net/                          |
// | PEAR          http://pear.php.net/package-info.php?pacid=137           |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at http://www.php.net/license/3_0.txt.               |
// | If you did not receive a copy of the PHP license and are unable to     |
// | obtain it through the world-wide-web, please send a note to            |
// | license@php.net so we can mail you a copy immediately.                 |
// +------------------------------------------------------------------------+
//

/**
 * Parser Data Structures
 * @package phpDocumentor
 * @subpackage ParserData
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserData.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
/**
 * Contains information about a PHP file, used to group procedural elements
 * together.
 * @package phpDocumentor
 * @subpackage ParserData
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserData.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserPage
{
    /**
     * Type is used by many functions to skip the hassle of if
     * <code>phpDocumentor_get_class($blah) == 'parserBlah'</code>
     * @var string
     */
    var $type = 'page';
    /**
     * not implemented in this version, will be used to link xml output pages
     * @var string
     */
    var $id = '';
    /**
     * filename.ext (no path)
     * @var string
     */
    var $file = '';
    /**
     * relative source location
     * @var string
     */
    var $sourceLocation = '';
    /**
     * phpdoc-safe name (only letters, numbers and _)
     * @var string
     */
    var $name = '';
    /**
     * @var string
     */
    var $category = 'default';
    /**
     * @var string
     */
    var $package = 'default';
    /**
     * @var string
     */
    var $subpackage = '';
    /**
     * @var string
     */
    var $parserVersion = PHPDOCUMENTOR_VER;
    /**
     * not implemented yet
     * file modification date, will be used for makefiles
     * @var string
     */
    var $modDate = '';
    /**
     * @var string full path this page represents
     */
    var $path = '';
    /**
     * Tokenized source code of the file
     * @var array
     */
    var $source = array();
    /**
     * Used to limit output, contains contents of --packageoutput commandline.
     * Does not increase parsing time.  Use --ignore for that
     * @see phpDocumentor_IntermediateParser::$packageoutput, Converter::$package_output
     * @var mixed either false or an array of packages
     */
    var $packageOutput = false;
    
    /**
     * sets package to default package
     * @global string default package name
     */
    function parserPage()
    {
        global $phpDocumentor_DefaultPackageName;
        $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
    }
    
    /**
     * @return string always "page"
     */
    function getType()
    {
        return 'page';
    }
    
    /**
     * Sets the source code of the file for highlighting.
     *
     * PHP 4.3.0+ passes an array of tokenizer tokens by line number.  PHP
     * 4.2.3- passes a string to be passed to {@link highlight_string()}
     * @param string|array
     */
    function setSource($source)
    {
        $this->source = $source;
    }
    
    /**
     * Sets the name to display in documentation (can be an alias set with @name)
     * @param string $file
     */
    function setFile($file)
    {
        $this->file = $file;
    }
    
    /**
     * @return string filename.ext or @name alias
     */
    function getFile()
    {
        if (!isset($this->file)) return false;
        return $this->file;
    }
    
    /**
     * @param string $path full path to file
     */
    function setPath($path)
    {
        // look for special windows case
        if(SMART_PATH_DELIMITER === '\\')
            $this->path = strtr($path,'/','\\');
        else
            $this->path = $path;
    }
    
    /**
     * @return string fully delimited path (OS-dependent format)
     */
    function getPath()
    {
        if (!isset($this->path)) return false;
        return $this->path;
    }
    
    /**
     * @param array $packages array of packages to display in documentation (package1,package2,...)
     * @see phpDocumentor_IntermediateParser::$packageoutput
     */
    function setPackageOutput($packages)
    {
        $this->packageOutput = $packages;
    }
    
    /**
     * @return array array of packages (package1,package2,...)
     * @see phpDocumentor_IntermediateParser::$packageoutput
     */
    function getPackageOutput()
    {
        return $this->packageOutput;
    }
    
    /**
     * @param string $name phpdoc-safe name (only _, numbers and letters) set by Parser::parse()
     * @see Parser::parse()
     */
    function setName($name)
    {
        $this->name = $name;
    }
    
    /**
     * @return string phpdoc-safe name (only _, numbers and letters)
     */
    function getName()
    {
        if (!isset($this->name)) return false;
        return $this->name;
    }
    
    /**
     * @param string $source path of this file relative to program root
     */
    function setSourceLocation($source)
    {
        $this->sourceLocation = $source;
    }
    
    /**
    * @param Converter
    * @param boolean if this parameter is true, it will truncate the source location to the
    * subdirectory of pear
     * @return string path of this file relative to program root
     */
    function getSourceLocation ($c,$pearize = false)
    {
        global $_phpDocumentor_options;
        if (!isset($this->sourceLocation)) return false;
        if ($pearize)
        {
            $sl = $this->sourceLocation;
            if (strpos($sl,'pear/'))
            {
                $sl = substr($sl,strpos($sl,'pear/') + 5);
                return $sl;
            } else
            {
                return str_replace($_phpDocumentor_options['Program_Root'] . PATH_DELIMITER,'',$sl);
            }
            return $sl;
        }
        return $this->sourceLocation;
    }
    /**
     * Not implemented in this version
     * @return boolean tell the parser whether to parse the file, otherwise
     *                   this function will retrieve the parsed data from external file
     */
    function getParseData()
    {
        return true;
    }
}

/**
 * Contains an in-memory representation of all documentable elements
 * ({@link parserPage}, {@link parserFunction}, {@link parserDefine},
 * {@link parserInclude}, {@link parserClass}, {@link parserMethod},
 * {@link parserVar}) and their DocBlocks ({@link parserDocBlock}).
 *
 * This class works in coordination with {@link phpDocumentor_IntermediateParser}
 * to take output from {@link Parser::handleEvent()} and create indexes, links,
 * and other assorted things (all documented in phpDocumentor_IntermediateParser
 * and {@link Converter})
 * @package phpDocumentor
 * @subpackage ParserData
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserData.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserData
{
    /**
     * {@link parserPage} element that is this parserData's parent, or false if
     * not set.
     * @var false|parserPage
     */
    var $parent = false;
    /**
     * array of parsed elements
     * @var array
     */
    var $elements = array();
    /**
     * array of parsed elements with @access private
     * @var array
     */
    var $privateelements = array();
    /**
     * array of parsed class elements
     * @var array
     */
    var $classelements = array();
    
    /**
     * @var parserTutorial|false
     */
    var $tutorial = false;
    /**
     * array of parsed class elements with @access private
     * @var array
     */
    var $privateclasselements = array();
    /**
     * array of links descended from {@link abstractLink}
     * @var array
     * @see pageLink, defineLink, classLink, functionLink, methodLink, varLink
     */
    var $links = array();
    /**
     * used by {@link phpDocumentor_IntermediateParser::handleDocBlock()} to
     * determine whether a docblock is a page-level docblock or not.  $clean is
     * true as long as only 0 or 1 docblock has been parsed, and no element
     * other than parserPage has been parsed
     * @var boolean
     */
    var $clean = true;
    /**
     * DocBlock ({@link parserDocBlock}) for this page, or false if not set
     * @var mixed
     */
    var $docblock = false;
    /**
     * Flag used to determine whether a page-level docblock is present
     * @var boolean
     * @access private
     */
    var $_explicitdocblock = false;
    /**
     * Type is used by many functions to skip the hassle of if
     * <code>phpDocumentor_get_class($blah) == 'parserBlah'</code>
     * always 'page', used in element indexing and conversion functions found in
     * {@link Converter}
     * @var string
     */
    var $type = 'page';
    
    /**
     * @param parserElement add a parsed element to the {@link $elements} array,
     *                      also sets {@link $clean} to false
     */
    function addElement(&$element)
    {
        $element->setPath($this->parent->path);
        if ($element->getType() == 'class' || $element->getType() == 'method' || $element->getType() == 'var'
            || $element->getType() == 'const')
        {
            $this->classelements[] = $element;
        } else
        {
            $this->elements[] = $element;
        }
        $this->clean = false;
    }
    
    /**
     * @param parserTutorial
     * @param Converter
     */
    function addTutorial($t,&$c)
    {
        $this->tutorial = new tutorialLink;
        $this->tutorial->addLink('',$t->path,$t->name,$t->package,$t->subpackage,$t->getTitle($c));
    }
    
    /**
     * If this file has a tutorial associated with it, returns a link to the
     * tutorial.
     * @return tutorialLink
     */
    function getTutorial()
    {
        return $this->tutorial;
    }
    
    /**
     * If the page-level DocBlock was present in the source, returns true
     * @return boolean
     */
    function hasExplicitDocBlock()
    {
        return $this->_explicitdocblock;
    }
    
    /**
     * Tells this page that its DocBlock was not implicit
     */
    function explicitDocBlock()
    {
        $this->_explicitdocblock = true;
    }
    
    /**
     * @param parserElement element to add a new link (descended from
     * {@link abstractLink})to the {@link $links} array
     * @param string classname for elements that are class-based (this may be
     *               deprecated in the future, as the classname should be
     *               contained within the element.  if $element is a page, this
     *               parameter is a package name
     * @param string subpackage name for page elements
     */
    function addLink(&$element,$classorpackage = '', $subpackage = '')
    {
        switch($element->type)
        {
            case 'function':
                $x = new functionLink;
                $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'define':
                $x = new defineLink;
                $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'global':
                $x = new globalLink;
                $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'class':
                $x = new classLink;
                $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'method':
                $x = new methodLink;
                $x->addLink($classorpackage, $this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'var':
                $x = new varLink;
                $x->addLink($classorpackage, $this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
                return $x;
            break;
            case 'page':
                if (empty($classorpackage)) $classorpackage = $GLOBALS['phpDocumentor_DefaultPackageName'];
                $x = new pageLink;
                $x->addLink($element->path,$element->name,$element->file,$classorpackage, $subpackage);
                return $x;
            break;
        }
    }
    
    function &getLink(&$c, $text = false)
    {
        return $c->getPageLink($this->parent->file, $this->docblock->package, $this->parent->path, $text);
    }
    
    /**
     * returns a list of all classes declared in a file
     * @param Converter &$c
     * @return array Format: array(packagename => parserClass,packagename => parserClass,...)
     */
    function getClasses(&$c)
    {
        $r = $c->classes->getClassesInPath($this->parent->path);
        $rr = array();
        if ($r)
        foreach($r as $class => $obj)
        {
            $rr[$obj->docblock->package][] = $obj;
        }
        return $rr;
    }
    
    /**
     * Get the output-safe filename (. changed to _)
     * @return string
     */
    function getName()
    {
        if (isset($this->parent) && $this->parent)
        return $this->parent->getName();
    }
    
    /**
     * @param parserPage parent element of this parsed data
     */
    function setParent(&$parent)
    {
        $this->parent = $parent;
    }
    
    /**
     * @return bool returns the value of {@link $clean}
     */
    function isClean()
    {
        return $this->clean;
    }
    
    /**
     * @param parserDocBlock
     * @see parserDocBlock
     */
    function setDocBlock(&$docblock)
    {
        $this->docblock = $docblock;
    }
}

/**
 * Base class for all elements
 * @package phpDocumentor
 * @subpackage ParserData
 * @abstract
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserData.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserBase
{
    /**
     * Type is used by many functions to skip the hassle of if phpDocumentor_get_class($blah) == 'parserBlah'
     * always base
     * @var string
     */
    var $type = 'base';
    /**
     * set to different things by its descendants
     * @abstract
     * @var mixed
     */
    var $value = false;

    /**
     * @return string returns value of {@link $type}
     */
    function getType()
    {
        return $this->type;
    }
    
    /**
     * @param mixed set the value of this element
     */
    function setValue($value)
    {
        $this->value = $value;
    }
    
    /**
     * @return mixed get the value of this element (element-dependent)
     */
    function getValue()
    {
        return $this->value;
    }
}


/**
 * Used to represent strings that contain inline tags, so that they can be properly parsed at link time
 * @package phpDocumentor
 * @subpackage ParserData
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserData.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserStringWithInlineTags extends parserBase
{
    /**
     * Type is used by many functions to skip the hassle of if phpDocumentor_get_class($blah) == 'parserBlah'
     * always '_string'
     * @var string
     */
    var $type = '_string';
    /** @access private */
    var $cache = false;
    /**
     * array of strings and {@link parserInlineTag}s
     * Format:
     * array(string1,string2,parserInlineTag1,string3,parserInlineTag2,...)
     * @var array
     */
    var $value = array();

    /**
     * equivalent to the . operator ($a = $b . $c)
     * @param mixed either a string or a {@link parserInlineTag}
     */
    function add($stringOrInlineTag)
    {
        if (is_string($stringOrInlineTag))
        {
            if (!count($this->value))
            {
                $this->value[] = $stringOrInlineTag;
                return;
            }
            if (is_string($this->value[count($this->value) - 1]))
            {
                $this->value[count($this->value) - 1] .= $stringOrInlineTag;
                return;
            } else
            {
                $this->value[] = $stringOrInlineTag;
                return;
            }
        } else
        {
            if (is_a($stringOrInlineTag,'parserinlinetag') && phpDocumentor_setup::checkIgnoreTag($stringOrInlineTag->inlinetype, true)) return;
            $this->value[] = $stringOrInlineTag;
        }
    }
    
    /**
     * Determine whether the string contains any inline tags
     * @tutorial inlinetags.pkg
     * @return boolean
     */
    function hasInlineTag()
    {
        for($i=0;$i<count($this->value);$i++)
        {
            if (is_a($this->value[$i],'parserinlinetag')) return true;
        }
        return false;
    }
    
    /**
     * Pass source code to any {@}source} tags contained within the string
     * for later conversion.
     * @param string|array source code ready to be highlighted
     */
    function setSource($source)
    {
        for($i=0;$i<count($this->value);$i++)
        {
            if (phpDocumentor_get_class($this->value[$i]) == 'parsersourceinlinetag')
            {
                $this->value[$i]->setSource($source);
            }
        }
    }

    /**
     * equivalent to trim(strlen($string))
     * @return integer length of the string this object represents
     */
    function trimmedStrlen()
    {
        $a = 0;
        for($i=0;$i<count($this->value);$i++)
        {
            if (is_string($this->value[$i]))
            {
                if ($i == 0)
                {
                    $a += strlen(ltrim($this->value[$i]));
                } elseif ($i == count($this->value[$i]) - 1)
                {
                    $a += strlen(chop($this->value[$i]));
                }
            } else
            {
                $a += $this->value[$i]->Strlen();
            }
        }
        return $a;
    }
    
    /**
     * return the string unconverted (all inline tags are taken out - this
     * should only be used in pre-parsing to see if any other text
     * is in the string)
     * @uses parserInlineTag::getString() removes inline tag length, as it is
     *       indeterminate until conversion.
     * @return string trimmed value
     */
    function getString($trim = true)
    {
        $a = '';
        for($i=0; $i<count($this->value); $i++)
        {
            if (is_string($this->value[$i]))
            {
                $a .= $this->value[$i];
            } else
            {
                $a .= $this->value[$i]->getString();
            }
        }
        if ($trim) $a = trim($a);
        return $a;
    }
    
    /**
     * Use to convert the string to a real string with all inline tags parsed and linked
     * @see Converter::returnSee()
     * @param Converter
     * @param boolean true if one needs to postprocess
     * @param boolean false if the output should not be trimmed
     */
    function Convert(&$converter,$postprocess = true, $trim = true)
    {
        if ($this->cache)
        {
            if ($converter->name == $this->cache['name'] && $converter->outputformat == $this->cache['output'] && $converter->checkState($this->cache['state']) && $this->cache['postprocess'] === $postprocess) return $this->cache['contents'];
            if ($converter->name != $this->cache['name']) {
                $this->cache = false;
            }
        }
        if (is_string($this->value)) return $this->value;
        $a = '';
        for($i=0; $i<count($this->value); $i++)
        {
            if (is_string($this->value[$i]))
            {
                if ($postprocess && !method_exists($converter,'postProcess')) var_dump('a',$converter);
                if ($postprocess) $a .= $converter->postProcess($this->value[$i]);
                else $a .= $this->value[$i];
            } else
            {
                $a .= $this->value[$i]->Convert($converter, $postprocess);
            }
        }
        if ($trim) {
            $a = trim($a);
        }
        $this->cache = array('name' => $converter->name,'output' => $converter->outputformat, 'contents' => $a, 'state' => $converter->getState(), 'postprocess' => $postprocess);
        return $a;
    }
}

?>