0af218a8f75523d040cae5ae9551b7db045285b2
[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 ,
102             "parent" => "",
103             "title" => "",
104             "permname" => "",
105             "modOrder" => "001",
106             "items" => array(
107         
108                 
109                 
110                 array(
111                     'name' => $this->name == '__construct' ? ('new ' . $this->class) : $this->name,
112                     'purpose' => $this->description->short,
113                     'stype' => 'function',
114                     '|xns' => 'Roo.doc',
115                     'xtype' => 'Entry',
116                     
117                     'items' => array(
118                         array(
119                             'name' => $this->name ,
120                             'is_static' => $this->isStatic ? true:false,
121                             'is_constructor' => $this->name == '__construct' ,
122                             'memberof' => $this->class,
123                             'returndesc' => $this->name == '_construct' ? '' : $this->description->return->desc,
124                             'returntype' => $this->name == '_construct' ? '' : $this->description->return->type,
125                             
126                             '|xns' => 'Roo.doc',
127                             'xtype' => 'Synopsis',
128                             'items' => $params
129                         ),
130                         array(
131                             'stype' => 'desc',
132                             '|xns' => 'Roo.doc',
133                             'xtype' => 'Section',
134                             'items' => array(
135                                 array(
136                                     'html' => $this->description->long,
137                                   '|xns' => 'Roo.doc',
138                                    'xtype' => 'Para',
139                                )
140                             )
141                         ),
142                         array(
143                             'stype' => 'parameter',
144                             '|xns' => 'Roo.doc',
145                             'xtype' => 'Section',
146                         ),
147                         array(
148                             'stype' => 'return',
149                             '|xns' => 'Roo.doc',
150                             'xtype' => 'Section',
151                         ),
152                         array(
153                             'stype' => 'example',
154                             '|xns' => 'Roo.doc',
155                             'xtype' => 'Section',
156                         )
157                     )   
158                 )
159             )
160         );
161                 
162                 
163         
164     }
165 }