home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Parse / Default / Function.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.6 KB  |  141 lines

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