1<?php
2
3/**
4 * This script is used to parse the parameter descriptions in pfcglobalconfig.class.php
5 * in order to keep the official documentation up to date.
6 */
7function pfc_generate_doc($f = NULL)
8{
9  $f = ($f != NULL) ? $f : dirname(__FILE__).'/../src/pfcglobalconfig.class.php';
10
11  $ct_params = array();
12//   $ct_params['http'] = array( 'proxy' => 'tcp://proxyout.inist.fr:8080', 'request_fulluri' => true );
13   $ct = stream_context_create($ct_params);
14  $data = file_get_contents($f, false, $ct);
15
16  $offset = 0;
17  if (preg_match('/class pfcGlobalConfig/',$data,$matches, PREG_OFFSET_CAPTURE, $offset))
18  {
19    $offset_start = $matches[0][1];
20  }
21  if (preg_match('/function pfcGlobalConfig/', $data, $matches, PREG_OFFSET_CAPTURE, $offset))
22  {
23    $offset_end = $matches[0][1];
24  }
25
26  $offset = $offset_start;
27  $plist = array();
28  $continue = true;
29  while ($offset < $offset_end)
30  {
31    $p = array();
32
33    // search for the begining of the description
34    if (preg_match('/\/\*\*/', $data, $matches1, PREG_OFFSET_CAPTURE, $offset))
35      $offset1 = $matches1[0][1];
36    else
37      $offset = $offset_end;
38
39    // search for the end of the description
40    if ($offset1 < $offset_end &&
41        preg_match('/\*\//', $data, $matches3, PREG_OFFSET_CAPTURE, $offset))
42    {
43      $offset3 = $matches3[0][1];
44
45      // search for the parameter description
46      $offset2 = $offset;
47      $p['desc'] = '';
48      while($offset2 < $offset3)
49      {
50        if (preg_match('/\s+\*\s+(.*)/', $data, $matches2, PREG_OFFSET_CAPTURE, $offset))
51        {
52          $offset2 = $matches2[1][1];
53          if ($offset2 < $offset3)
54          {
55            $offset = $offset2;
56            $p['desc'] .= ' '.$matches2[1][0];
57          }
58        }
59        else
60          break;
61      }
62      $p['desc'] = trim($p['desc']);
63
64      // search for the parameter name/default value
65      if (preg_match('/var\s+\$([a-z_]+)\s+=\s+(.*);/is', $data, $matches4, PREG_OFFSET_CAPTURE, $offset))
66      {
67        $offset = $matches4[1][1];
68        $p['name']  = $matches4[1][0];
69        $p['value'] = $matches4[2][0];
70      }
71      else
72        $offset = $offset_end;
73    }
74    else
75      $offset = $offset_end;
76
77    if (count($p) > 0) $plist[] = $p;
78  }
79  return $plist;
80}
81
82?>
83