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         $items = array(
99             array(
100                 'name' => $this->name ,
101                 'is_static' => $this->isStatic ? true:false,
102                 'is_constructor' => $this->name == '__construct' ,
103                 'memberof' => $this->class,
104                 'returndesc' => $this->name == '_construct' ? '' : $this->description->return->desc,
105                 'returntype' => $this->name == '_construct' ? '' : $this->description->return->type,
106                 
107                 '|xns' => 'Roo.doc',
108                 'xtype' => 'Synopsis',
109                 'items' => $params
110             ),
111             array(
112                 'stype' => 'desc',
113                 '|xns' => 'Roo.doc',
114                 'xtype' => 'Section',
115                 'items' => array(
116                     array(
117                         'html' => $this->description->long,
118                       '|xns' => 'Roo.doc',
119                        'xtype' => 'Para',
120                    )
121                 )
122             ),
123             array(
124                 'stype' => 'parameter',
125                 '|xns' => 'Roo.doc',
126                 'xtype' => 'Section',
127             ),
128           
129         );
130         
131         if ( $this->name != '__construct') {
132             $items[] = array(
133                 'stype' => 'return',
134                 '|xns' => 'Roo.doc',
135                 'xtype' => 'Section',
136             );
137         }
138         if ( !empty($this->description->throws) {
139             $items[] = array(
140                 'stype' => 'throws',
141                 '|xns' => 'Roo.doc',
142                 'xtype' => 'Throws',
143             );
144         }
145         
146         
147                         /* -- fixme - needs to read from an example file..
148                         array(
149                             'stype' => 'example',
150                             '|xns' => 'Roo.doc',
151                             'xtype' => 'Section',
152                         )
153                         */
154         
155         return array(
156             "name" => $this->name ,
157             "parent" => "",
158             "title" => "",
159             "permname" => "",
160             "modOrder" => "001",
161             "items" => array(
162         
163                 
164                 
165                 array(
166                     'name' => $this->name == '__construct' ? ('new ' . $this->class) : $this->name,
167                     'purpose' => $this->description->short,
168                     'stype' => 'function',
169                     '|xns' => 'Roo.doc',
170                     'xtype' => 'Entry',
171                     
172                     'items' => $items
173                          
174                     
175                 )
176             )
177         );
178                 
179                 
180         
181     }
182 }