CodeDoc/Data/Method.php
[PHP_CodeDoc] / CodeDoc / Data / Method.php
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license,      |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/2_02.txt.                                 |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Authors: Alan Knowles <alan@akbkhome.com>                      |
17 // +----------------------------------------------------------------------+
18 //
19 require_once 'PHP/CodeDoc/Data.php';
20 /**
21 *   Method and Function Data Container
22 *
23 *   @package  PHP_CodeDoc
24 *   @access   public
25 *   @author   Alan Knowles <alan@akbkhome.com>
26 *
27 */
28 class PHP_CodeDoc_Data_Method extends PHP_CodeDoc_Data {
29     var $id;          // id in the Classes Operations array (not used yet)
30     var $name;        // the name of the method
31     var $type;        // Private | Public
32     var $class;       // what class it is defined in
33     var $visibility;  // Not used (always 1)
34     var $Param;       // Array of Methods Parameters.
35    
36     var $description; // phpdoc class
37     var  $isPublic = 1;
38     var $isStatic = 0;
39     var $isFinal = 0;
40     
41     function __construct()
42     {
43         $this->description = new PHP_CodeDoc_Data_PhpDoc();
44     }
45
46     function mergePhpDoc() {
47         $isOptional = FALSE;
48         foreach (array_keys($this->Param) as $i) {
49             if (@$this->description->param[$i]) {
50                 $this->Param[$i]->type = @$this->description->param[$i]->type;
51                 $this->Param[$i]->desc = @$this->description->param[$i]->desc;
52             }
53             $this->Param[$i]->shortname = substr($this->Param[$i]->name,1);
54             
55             if (isset($this->Param[$i]->Value)) {
56                 $isOptional =TRUE;
57             }
58             if (!isset($this->Param[$i]->Value) && $isOptional) {
59                 PHP_CodeDoc_Error::log("Missing optional value in method",$this);
60             }
61             $this->Param[$i]->isOptional=$isOptional ;
62         }
63         
64     
65     }
66      function toJs()
67     {
68         if ($this->type == 'Private') {
69             return false;
70         }
71         
72         $def_param = array(
73                     'desc' => '',
74                     'is_optional' => false,
75                     'name' => '',
76                     'type' => '',
77                     '|xns' => 'Roo.doc',
78                     'xtype' => 'Param',
79                     
80                 );
81         $params = array();
82         foreach($this->Param as $i=>$obj) {
83             if (!isset($params[$i])) {
84                 $params[$i] = $def_param;
85             }
86             $params[$i]['name'] = $obj->name;
87         }
88         foreach($this->description->param as $i=>$obj) {
89             if (!isset($params[$i])) {
90                 $params[$i] = $def_param;
91             }
92             $params[$i]['desc'] = $obj->desc;
93             $params[$i]['type'] = $obj->type;
94             // fixme - is_optional and default values...
95         }    
96         
97         
98         return
99         
100         array(
101             "name" => $this->name == '__construct' ? ('new ' . $this->class) : $this->name,
102             "parent" => "",
103             "title" => "",
104             "permname" => "",
105             "modOrder" => "001",
106             "items" => array(
107         
108                 
109                 
110                 array(
111                     'name' => $this->name,
112                     'purpose' => $this->description->short,
113                     'stype' => 'function',
114                     '|xns' => 'Roo.doc',
115                     'xtype' => 'Entry',
116                     'items' => array(
117                         array(
118                             'name' => $this->name == '__construct' ? ('new ' . $this->class) : $this->name,
119                             'is_static' => $this->isStatic ? true:false,
120                             'memberof' => $this->class,
121                             'returndesc' => $this->name == '_construct' ? '' : $this->description->return->desc,
122                             'returntype' => $this->name == '_construct' ? '' : $this->description->return->type,
123                             
124                             '|xns' => 'Roo.doc',
125                             'xtype' => 'Synopsis',
126                             'items' => $params
127                         ),
128                         array(
129                             'stype' => 'desc',
130                             '|xns' => 'Roo.doc',
131                             'xtype' => 'Section',
132                             'items' => array(
133                                 array(
134                                     'html' => $this->description->long,
135                                   '|xns' => 'Roo.doc',
136                                    'xtype' => 'Para',
137                                )
138                             )
139                         ),
140                         array(
141                             'stype' => 'parameter',
142                             '|xns' => 'Roo.doc',
143                             'xtype' => 'Section',
144                         ),
145                         array(
146                             'stype' => 'return',
147                             '|xns' => 'Roo.doc',
148                             'xtype' => 'Section',
149                         ),
150                         array(
151                             'stype' => 'example',
152                             '|xns' => 'Roo.doc',
153                             'xtype' => 'Section',
154                         )
155                     )   
156                 )
157             )
158         );
159                 
160                 
161         
162     }
163 }