includes/wikiengine/Parse/Mediawiki/Function.php
changeset 1027 98c052fc3337
parent 1026 f0431eb8161e
child 1028 dde4416dea00
equal deleted inserted replaced
1026:f0431eb8161e 1027:98c052fc3337
     1 <?php
       
     2 
       
     3 /**
       
     4 * 
       
     5 * Parses for an API function documentation block.
       
     6 * 
       
     7 * @category Text
       
     8 * 
       
     9 * @package Text_Wiki
       
    10 * 
       
    11 * @author Paul M. Jones <pmjones@php.net>
       
    12 * 
       
    13 * @license LGPL
       
    14 * 
       
    15 * @version $Id: Function.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
       
    16 * 
       
    17 */
       
    18 
       
    19 /**
       
    20 * 
       
    21 * Parses for an API function documentation block.
       
    22 *
       
    23 * @category Text
       
    24 * 
       
    25 * @package Text_Wiki
       
    26 * 
       
    27 * @author Paul M. Jones <pmjones@php.net>
       
    28 * 
       
    29 */
       
    30 
       
    31 class Text_Wiki_Parse_Function extends Text_Wiki_Parse {
       
    32 
       
    33     var $regex = '/^(\<function\>)\n(.+)\n(\<\/function\>)(\s|$)/Umsi';
       
    34     
       
    35     function process(&$matches)
       
    36     {
       
    37         // default options
       
    38         $opts = array(
       
    39             'name' => null,
       
    40             'access' => null,
       
    41             'return' => null,
       
    42             'params' => array(),
       
    43             'throws' => array()
       
    44         );
       
    45         
       
    46         // split apart the markup lines and loop through them
       
    47         $lines = explode("\n", $matches[2]);
       
    48         foreach ($lines as $line) {
       
    49             
       
    50             // skip blank lines
       
    51             if (trim($line) == '') {
       
    52                 continue;
       
    53             }
       
    54             
       
    55             // find the first ':' on the line; the left part is the 
       
    56             // type, the right part is the value. skip lines without
       
    57             // a ':' on them.
       
    58             $pos = strpos($line, ':');
       
    59             if ($pos === false) {
       
    60                 continue;
       
    61             }
       
    62             
       
    63             // $type is the line type: name, access, return, param, throws
       
    64             // 012345678901234
       
    65             // name: something
       
    66             $type = trim(substr($line, 0, $pos));
       
    67             $val = trim(substr($line, $pos+1));
       
    68             
       
    69             switch($type) {
       
    70             
       
    71             case 'a':
       
    72             case 'access':
       
    73                 $opts['access'] = $val;
       
    74                 break;
       
    75                 
       
    76             case 'n':
       
    77             case 'name':
       
    78                 $opts['name'] = $val;
       
    79                 break;
       
    80                 
       
    81             case 'p':
       
    82             case 'param':
       
    83                 $tmp = explode(',', $val);
       
    84                 $k = count($tmp);
       
    85                 if ($k == 1) {
       
    86                     $opts['params'][] = array(
       
    87                         'type' => $tmp[0],
       
    88                         'descr' => null,
       
    89                         'default' => null
       
    90                     );
       
    91                 } elseif ($k == 2) {
       
    92                     $opts['params'][] = array(
       
    93                         'type' => $tmp[0],
       
    94                         'descr' => $tmp[1],
       
    95                         'default' => null
       
    96                     );
       
    97                 } else {
       
    98                     $opts['params'][] = array(
       
    99                         'type' => $tmp[0],
       
   100                         'descr' => $tmp[1],
       
   101                         'default' => $tmp[2]
       
   102                     );
       
   103                 }
       
   104                 break;
       
   105             
       
   106             case 'r':
       
   107             case 'return':
       
   108             case 'returns':
       
   109                 $opts['return'] = $val;
       
   110                 break;
       
   111             
       
   112             case 't':
       
   113             case 'throws':
       
   114                 $tmp = explode(',', $val);
       
   115                 $k = count($tmp);
       
   116                 if ($k == 1) {
       
   117                     $opts['throws'][] = array(
       
   118                         'type' => $tmp[0],
       
   119                         'descr' => null
       
   120                     );
       
   121                 } else {
       
   122                     $opts['throws'][] = array(
       
   123                         'type' => $tmp[0],
       
   124                         'descr' => $tmp[1]
       
   125                     );
       
   126                 }
       
   127                 break;
       
   128         
       
   129             default:
       
   130                 $opts[$type] = $val;
       
   131                 break;
       
   132             
       
   133             }
       
   134         }
       
   135         
       
   136         // add the token back in place
       
   137         return $this->wiki->addToken($this->rule, $opts) . $matches[4];
       
   138     }
       
   139 }
       
   140 
       
   141 ?>