Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Function.php

Documentation is available at Function.php

  1. <?php
  2.  
  3. /*
  4. <function name="" return="" access="">
  5. type, descr
  6. type, descr, default (if there is a default value, then it is optional!)
  7. </function>
  8. */
  9.  
  10.  
  11.     var $regex = '/^(\<function\>)\n(.+)\n(\<\/function\>)(\s|$)/Umsi';
  12.     
  13.     function process(&$matches)
  14.     {
  15.         // default options
  16.         $opts = array(
  17.             'name' => null,
  18.             'access' => 'public',
  19.             'return' => 'void',
  20.             'params' => array(),
  21.             'throws' => array()
  22.         );
  23.         
  24.         // split apart the markup lines and loop through them
  25.         $lines explode("\n"$matches[2]);
  26.         foreach ($lines as $line{
  27.             
  28.             // skip blank lines
  29.             if (trim($line== ''{
  30.                 continue;
  31.             }
  32.             
  33.             // find the first ':' on the line; the left part is the 
  34.             // type, the right part is the value. skip lines without
  35.             // a ':' on them.
  36.             $pos strpos($line':');
  37.             if ($pos === false{
  38.                 continue;
  39.             }
  40.             
  41.             // $type is the line type: name, access, return, param, throws
  42.             // 012345678901234
  43.             // name: something
  44.             $type trim(substr($line0$pos));
  45.             $val trim(substr($line$pos+1));
  46.             
  47.             switch($type{
  48.             
  49.             case 'param':
  50.                 $tmp explode(','$val);
  51.                 $k count($tmp);
  52.                 if ($k == 1{
  53.                     $opts['params'][= array(
  54.                         'type' => $tmp[0],
  55.                         'descr' => null,
  56.                         'default' => null
  57.                     );
  58.                 elseif ($k == 2{
  59.                     $opts['params'][= array(
  60.                         'type' => $tmp[0],
  61.                         'descr' => $tmp[1],
  62.                         'default' => null
  63.                     );
  64.                 else {
  65.                     $opts['params'][= array(
  66.                         'type' => $tmp[0],
  67.                         'descr' => $tmp[1],
  68.                         'default' => $tmp[2]
  69.                     );
  70.                 }
  71.                 break;
  72.         
  73.             case 'throws':
  74.                 $opts[$type][$val;
  75.                 
  76.             case 'name':
  77.             case 'return':
  78.             case 'access':
  79.             default:
  80.                 if ($type == 'returns'{
  81.                     $type 'return';
  82.                 }
  83.                 
  84.                 if ($type == 'throw'{
  85.                     $type 'throws';
  86.                 }
  87.                 
  88.                 $opts[$type$val;
  89.                 break;
  90.             
  91.             }
  92.         }
  93.         
  94.         // add the token back in place
  95.         return $this->wiki->addToken($this->rule$opts$matches[4];
  96.     }
  97. }
  98.  
  99. ?>

Documentation generated on Mon, 11 Mar 2019 13:56:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.