Subversion Repositories PHPX

Rev

Rev 13 | Rev 16 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13 Rev 14
1
<?php
1
<?php
2
2
3
require_once 'global.inc';
3
require_once 'global.inc';
4
4
5
define('FEATURES_ENCODING',
5
define('FEATURES_ENCODING',
6
  mb_detect_encoding(file_get_contents($_SERVER['SCRIPT_FILENAME'])));
6
  mb_detect_encoding(file_get_contents($_SERVER['SCRIPT_FILENAME'])));
7
7
8
/**
8
/**
9
 * A list of language features with URNs definitions
9
 * A list of language features with URNs definitions
10
 * for reference links.
10
 * for reference links.
11
 */
11
 */
12
class FeatureList
12
class FeatureList
13
{
13
{
14
  public $versions = array();
14
  public $versions = array();
15
 
15
 
16
  /**
16
  /**
17
   * Versions of implementations that are considered safe.
17
   * Versions of implementations that are considered safe.
18
   * A feature is considered safe if it does not require
18
   * A feature is considered safe if it does not require
19
   * an implementation version above these versions.
19
   * an implementation version above these versions.
20
   *
20
   *
21
   * @var Array[string=>string]
21
   * @var Array[string=>string]
22
   */
22
   */
23
  public $safeVersions = array();
23
  public $safeVersions = array();
24
 
24
 
25
  /**
25
  /**
26
   * URNs that can be used for reference links.
26
   * URNs that can be used for reference links.
27
   *
27
   *
28
   * @var Array[string=>string]
28
   * @var Array[string=>string]
29
   */
29
   */
30
  protected $urns = array();
30
  protected $urns = array();
31
 
31
 
32
  /**
32
  /**
33
   * The list of language features
33
   * The list of language features
34
   *
34
   *
35
   * @var array[Features]
35
   * @var array[Features]
36
   */
36
   */
37
  protected $items = array();
37
  protected $items = array();
38
 
38
 
39
  /**
39
  /**
40
   * Determines the number of printed items the table headings should be repeated
40
   * Determines the number of printed items the table headings should be repeated
41
   *
41
   *
42
   * @var int
42
   * @var int
43
   */
43
   */
44
  protected $headerRepeat = 25;
44
  protected $headerRepeat = 25;
45
45
46
  /**
46
  /**
47
   * Initializes the FeatureList object
47
   * Initializes the FeatureList object
48
   *
48
   *
49
   * @param array|Object $a
49
   * @param array|Object $a
50
   * @return FeatureList
50
   * @return FeatureList
51
   */
51
   */
52
  public function __construct($a)
52
  public function __construct($a)
53
  {
53
  {
54
    $aVars = get_class_vars(get_class($this));
54
    $aVars = get_class_vars(get_class($this));
55
   
55
   
56
    while ((list($key, $value) = each($aVars)))
56
    while ((list($key, $value) = each($aVars)))
57
    {
57
    {
58
      if (isset($a[$key]))
58
      if (isset($a[$key]))
59
      {
59
      {
60
        $this->$key = $a[$key];
60
        $this->$key = $a[$key];
61
      }
61
      }
62
    }
62
    }
63
   
63
   
64
    /* Inform items of ourself so that URNs can be used for links */
64
    /* Inform items of ourself so that URNs can be used for links */
65
    if (is_array($this->items))
65
    if (is_array($this->items))
66
    {
66
    {
67
      foreach ($this->items as &$item)
67
      foreach ($this->items as &$item)
68
      {
68
      {
69
        $item->setList($this);
69
        $item->setList($this);
70
      }
70
      }
71
    }
71
    }
72
   
72
   
73
    /* resolve URN references that are URNs */
73
    /* resolve URN references that are URNs */
74
    if (is_array($this->urns))
74
    if (is_array($this->urns))
75
    {
75
    {
76
      foreach ($this->urns as &$urn)
76
      foreach ($this->urns as &$urn)
77
      {
77
      {
78
        if (($url = $this->resolveURN($urn)))
78
        if (($url = $this->resolveURN($urn)))
79
        {
79
        {
80
          $urn = $url;
80
          $urn = $url;
81
        }
81
        }
82
      }
82
      }
83
    }
83
    }
84
  }
84
  }
85
 
85
 
86
  public function printHeaders()
86
  public function printHeaders()
87
  {
87
  {
88
    foreach ($this->versions as $ver)
88
    foreach ($this->versions as $ver)
89
    {
89
    {
90
?>
90
?>
91
          <th><?php echo $ver; ?></th>
91
          <th><?php echo $ver; ?></th>
92
<?php
92
<?php
93
    }
93
    }
94
  }
94
  }
95
   
95
   
96
  /**
96
  /**
97
   * Prints the list of features.
97
   * Prints the list of features.
98
   *
98
   *
99
   * @see Feature::printMe()
99
   * @see Feature::printMe()
100
   */
100
   */
101
  public function printItems()
101
  public function printItems()
102
  {
102
  {
103
    $counter = 0;
103
    $counter = 0;
104
    $headerRepeat = $this->headerRepeat;
104
    $headerRepeat = $this->headerRepeat;
105
    $repeatHeaders = ($headerRepeat > 1);
105
    $repeatHeaders = ($headerRepeat > 1);
106
   
106
   
107
    foreach ($this->items as $feature)
107
    foreach ($this->items as $feature)
108
    {
108
    {
109
      if ($feature instanceof Feature)
109
      if ($feature instanceof Feature)
110
      {
110
      {
111
        if ($repeatHeaders
111
        if ($repeatHeaders
112
            && $counter > 1
112
            && $counter > 1
113
            && $counter % $headerRepeat === 0)
113
            && $counter % $headerRepeat === 0)
114
        {
114
        {
115
?>
115
?>
116
        <tr class="header">
116
        <tr class="header">
117
          <th>Feature</th>
117
          <th>Feature</th>
118
          <?php $this->printHeaders(); ?>
118
          <?php $this->printHeaders(); ?>
119
        </tr>
119
        </tr>
120
<?php
120
<?php
121
        }
121
        }
122
       
122
       
123
        $feature->printMe();
123
        $feature->printMe();
124
       
124
       
125
        $counter++;
125
        $counter++;
126
      }
126
      }
127
    }
127
    }
128
  }
128
  }
129
 
129
 
130
  /**
130
  /**
131
   * Resolves a URN according to the value of the
131
   * Resolves a URN according to the value of the
132
   * object's <code>$urn</code> property.
132
   * object's <code>$urn</code> property.
133
   *
133
   *
134
   * @param string $urn
134
   * @param string $urn
135
   *   URN to be resolved
135
   *   URN to be resolved
136
   * @return string|boolean
136
   * @return string|boolean
137
   *   The resolved URN if successful,
137
   *   The resolved URN if successful,
138
   *   <code>false</code> otherwise.
138
   *   <code>false</code> otherwise.
139
   */
139
   */
140
  public function resolveURN($urn)
140
  public function resolveURN($urn)
141
  {
141
  {
142
    if (is_array($this->urns))
142
    if (is_array($this->urns))
143
    {
143
    {
144
      $reURN = '|^(.+?):(?!//)|';
144
      $reURN = '|^(.+?):(?!//)|';
145
     
145
     
146
      if (preg_match($reURN, $urn, $m) && isset($this->urns[$m[1]]))
146
      if (preg_match($reURN, $urn, $m) && isset($this->urns[$m[1]]))
147
      {
147
      {
148
        return preg_replace($reURN, $this->urns[$m[1]], $urn);
148
        return preg_replace($reURN, $this->urns[$m[1]], $urn);
149
      }
149
      }
150
    }
150
    }
151
151
152
    return $urn;
152
    return $urn;
153
  }
153
  }
154
}
154
}
155
155
156
/**
156
/**
157
 * A language feature.
157
 * A language feature.
158
 */
158
 */
159
class Feature
159
class Feature
160
{
160
{
161
  /**
161
  /**
162
   * Fragment identifiers to be defined for quickly accessing
162
   * Fragment identifiers to be defined for quickly accessing
163
   * the feature description.
163
   * the feature description.
164
   *
164
   *
165
   * @var Array[String]
165
   * @var Array[String]
166
   */
166
   */
167
  protected $anchors = array();
167
  protected $anchors = array();
168
 
168
 
169
  /**
169
  /**
170
   * Value of the explanatory <code>title</code> attribute for the feature.
170
   * Value of the explanatory <code>title</code> attribute for the feature.
171
   *
171
   *
172
   * @var string
172
   * @var string
173
   */
173
   */
174
  protected $title = '';
174
  protected $title = '';
175
 
175
 
176
  /**
176
  /**
177
   * Name or example code of the feature
177
   * Name or example code of the feature
178
   *
178
   *
179
   * @var string
179
   * @var string
180
   */
180
   */
181
  protected $content = '';
181
  protected $content = '';
182
   
182
   
183
  /**
183
  /**
184
   * Description of the feature.  Displayed directly if code is missing,
184
   * Description of the feature.  Displayed directly if code is missing,
185
   * otherwise used as `title' attribute value.
185
   * otherwise used as `title' attribute value.
186
   *
186
   *
187
   * @var string
187
   * @var string
188
   */
188
   */
189
  protected $descr = '';
189
  protected $descr = '';
190
 
190
 
191
  /**
191
  /**
192
   * Versions that support this feature
192
   * Versions that support this feature
193
   *
193
   *
194
   * @var Array
194
   * @var Array
195
   */
195
   */
196
  protected $versions = array();
196
  protected $versions = array();
197
   
197
   
198
  /**
198
  /**
199
   * Reference to the FeatureList that this feature belongs to
199
   * Reference to the FeatureList that this feature belongs to
200
   *
200
   *
201
   * @var FeatureList
201
   * @var FeatureList
202
   */
202
   */
203
  protected $list = null;
203
  protected $list = null;
204
 
204
 
205
  public function setList(&$oList)
205
  public function setList(&$oList)
206
  {
206
  {
207
    $this->list =& $oList;
207
    $this->list =& $oList;
208
  }
208
  }
209
209
210
  /**
210
  /**
211
   * Creates a new Feature object, using values from the passed parameters
211
   * Creates a new Feature object, using values from the passed parameters
212
   * array.
212
   * array.
213
   *
213
   *
214
   * @param array|Object $params
214
   * @param array|Object $params
215
   * @return Feature
215
   * @return Feature
216
   */
216
   */
217
  public function __construct($params = array())
217
  public function __construct($params = array())
218
  {
218
  {
219
    $aVars = get_class_vars(get_class($this));
219
    $aVars = get_class_vars(__CLASS__);
220
   
220
   
221
    while ((list($key, $value) = each($aVars)))
221
    while ((list($key, $value) = each($aVars)))
222
    {
222
    {
223
      if (isset($params[$key]))
223
      if (isset($params[$key]))
224
      {
224
      {
225
        $this->$key = $params[$key];
225
        $this->$key = $params[$key];
226
      }
226
      }
227
    }
227
    }
228
  }
228
  }
229
 
229
 
230
  /**
230
  /**
231
   * Returns <code>' class="safe"'</code> if the feature
231
   * Returns <code>' class="safe"'</code> if the feature
232
   * can be considered safe.  The required information
232
   * can be considered safe.  The required information
233
   * is stored in the <code>safeVersions</code> property
233
   * is stored in the <code>safeVersions</code> property
234
   * of the associated <code>FeatureList</code> object.
234
   * of the associated <code>FeatureList</code> object.
235
   *
235
   *
236
   * @return string
236
   * @return string
237
   * @see FeatureList::defaultSafeVersions
237
   * @see FeatureList::defaultSafeVersions
238
   */
238
   */
239
  protected function getSafeStr()
239
  protected function getSafeStr()
240
  {
240
  {
241
    if (!is_null($this->list))
241
    if (!is_null($this->list))
242
    {
242
    {
243
      foreach ($this->list->safeVersions as $impl => &$safeVer)
243
      foreach ($this->list->safeVersions as $impl => &$safeVer)
244
      {
244
      {
245
        $thisImplVer =& $this->versions[$impl];
245
        $thisImplVer =& $this->versions[$impl];
246
        if (is_array($thisImplVer))
246
        if (is_array($thisImplVer))
247
        {
247
        {
248
          if (isset($thisImplVer['tested']) && !is_bool($thisImplVer['tested']))
248
          if (isset($thisImplVer['tested']) && !is_bool($thisImplVer['tested']))
249
          {
249
          {
250
            $thisImplVer =& $thisImplVer['tested'];
250
            $thisImplVer =& $thisImplVer['tested'];
251
          }
251
          }
252
          else
252
          else
253
        {
253
        {
254
            $thisImplVer =& $thisImplVer[0];
254
            $thisImplVer =& $thisImplVer[0];
255
          }
255
          }
256
        }
256
        }
257
       
257
       
258
        /* DEBUG */
258
        /* DEBUG */
259
        // echo " $impl=$thisImplVer ";
259
        // echo " $impl=$thisImplVer ";
260
       
260
       
261
        if (preg_match('/^-?$/', $thisImplVer) || $thisImplVer > $safeVer)
261
        if (preg_match('/^-?$/', $thisImplVer) || $thisImplVer > $safeVer)
262
        {
262
        {
263
          return '';
263
          return '';
264
        }
264
        }
265
      }
265
      }
266
     
266
     
267
      return ' class="safe"';
267
      return ' class="safe"';
268
    }
268
    }
269
    else
269
    else
270
    {
270
    {
271
      return '';
271
      return '';
272
    }
272
    }
273
  }
273
  }
274
 
274
 
275
  protected function getTitleStr()
275
  protected function getTitleStr()
276
  {
276
  {
277
    if (!empty($this->title))
277
    if (!empty($this->title))
278
    {
278
    {
279
      return " title=\"{$this->title}\"";
279
      return " title=\"{$this->title}\"";
280
    }
280
    }
281
    else
281
    else
282
    {
282
    {
283
      return '';
283
      return '';
284
    }
284
    }
285
  }
285
  }
286
 
286
 
287
  protected function getAnchors()
287
  protected function getAnchors()
288
  {
288
  {
289
    $result = array();
289
    $result = array();
290
 
290
 
291
    foreach ($this->anchors as $anchor)
291
    foreach ($this->anchors as $anchor)
292
    {
292
    {
293
      $result[] = "<a name=\"{$anchor}\"";
293
      $result[] = "<a name=\"{$anchor}\"";
294
     
294
     
295
      if (preg_match('/^[a-z][a-z0-9_:.-]*/i', $anchor))
295
      if (preg_match('/^[a-z][a-z0-9_:.-]*/i', $anchor))
296
      {
296
      {
297
        $result[] = " id=\"{$anchor}\"";
297
        $result[] = " id=\"{$anchor}\"";
298
      }
298
      }
299
     
299
     
300
      $result[] = '></a>';
300
      $result[] = '></a>';
301
    }
301
    }
302
   
302
   
303
    return join('', $result);
303
    return join('', $result);
304
  }
304
  }
305
305
306
  protected function getAssumed($v)
306
  protected function getAssumed($v)
307
  {
307
  {
308
    if (is_array($v) && isset($v['assumed']) && $v['assumed'])
308
    if (is_array($v) && isset($v['assumed']) && $v['assumed'])
309
    {
309
    {
310
      return ' class="assumed"';
310
      return ' class="assumed"';
311
    }
311
    }
312
   
312
   
313
    return '';
313
    return '';
314
  }
314
  }
315
315
316
  protected function getTested($v)
316
  protected function getTested($v)
317
  {
317
  {
318
    if (is_array($v) && isset($v['tested']) && $v['tested'])
318
    if (is_array($v) && isset($v['tested']) && $v['tested'])
319
    {
319
    {
320
      return ' class="tested"';
320
      return ' class="tested"';
321
    }
321
    }
322
   
322
   
323
    return '';
323
    return '';
324
  }
324
  }
325
 
325
 
326
  /**
326
  /**
327
   * Returns the version of a feature.
327
   * Returns the version of a feature.
328
   *
328
   *
329
   * @param string|VersionInfo $vInfo
329
   * @param string|VersionInfo $vInfo
330
   * @return mixed
330
   * @return mixed
331
   */
331
   */
332
  protected function getVer($vInfo)
332
  protected function getVer($vInfo)
333
  {
333
  {
334
    if (is_array($vInfo))
334
    if (is_array($vInfo))
335
    {
335
    {
336
      /* TODO: Return all versions: documented, assumed, and tested */
336
      /* TODO: Return all versions: documented, assumed, and tested */
337
      $vNumber = (isset($vInfo['tested'])
337
      $vNumber = (isset($vInfo['tested'])
338
                  && gettype($vInfo['tested']) !== 'boolean')
338
                  && gettype($vInfo['tested']) !== 'boolean')
339
                     ? $vInfo['tested']
339
                     ? $vInfo['tested']
340
                     : $vInfo[0];
340
                     : $vInfo[0];
341
      $section = isset($vInfo['section'])
341
      $section = isset($vInfo['section'])
342
                   ? ' <span class="section" title="Specification section">['
342
                   ? ' <span class="section" title="Specification section">['
343
                      . $vInfo['section'] . ']</span>'
343
                      . $vInfo['section'] . ']</span>'
344
                   : '';
344
                   : '';
345
     
345
     
346
      if (isset($vInfo['urn']))
346
      if (isset($vInfo['urn']))
347
      {
347
      {
348
        if ($this->list instanceof FeatureList)
348
        if ($this->list instanceof FeatureList)
349
        {
349
        {
350
          $url = $this->list->resolveURN($vInfo['urn']);
350
          $url = $this->list->resolveURN($vInfo['urn']);
351
          $vNumber = '<a href="' . $url . '">' . $vNumber
351
          $vNumber = '<a href="' . $url . '">' . $vNumber
352
            . ($section ? $section : '') . '</a>';
352
            . ($section ? $section : '') . '</a>';
353
        }
353
        }
354
      }
354
      }
355
      else if ($section)
355
      else if ($section)
356
      {
356
      {
357
        $vNumber .= $section;
357
        $vNumber .= $section;
358
      }
358
      }
359
359
360
      $vInfo = $vNumber;
360
      $vInfo = $vNumber;
361
    }
361
    }
362
362
363
    return ($vInfo === '-')
363
    return ($vInfo === '-')
364
      ? '<span title="Not supported">&#8722;</span>'
364
      ? '<span title="Not supported">&#8722;</span>'
365
      : $vInfo;
365
      : $vInfo;
366
  }
366
  }
367
   
367
   
368
  protected static function shl($s)
368
  protected static function shl($s)
369
  {
369
  {
370
    /* stub */
370
    /* stub */
371
  }
371
  }
372
 
372
 
373
  public function printMe()
373
  public function printMe()
374
  {
374
  {
375
    ?>
375
    ?>
376
<tr<?php echo $this->getSafeStr(); ?>>
376
<tr<?php echo $this->getSafeStr(); ?>>
377
          <th<?php echo $this->getTitleStr(); ?>><?php
377
          <th<?php echo $this->getTitleStr(); ?>><?php
378
            echo $this->getAnchors();
378
            echo $this->getAnchors();
379
            echo /*preg_replace_callback(
379
            echo /*preg_replace_callback(
380
              '#(<code>)(.+?)(</code>)#',
380
              '#(<code>)(.+?)(</code>)#',
381
              array('self', 'shl'),*/
381
              array('self', 'shl'),*/
382
              preg_replace('/&hellip;/', '&#8230;', $this->content)/*)*/;
382
              preg_replace('/&hellip;/', '&#8230;', $this->content)/*)*/;
383
            ?></th>
383
            ?></th>
384
<?php
384
<?php
385
    $versions = $this->versions;
385
    $versions = $this->versions;
386
    if (!is_null($this->list))
386
    if (!is_null($this->list))
387
    {
387
    {
388
      $versions =& $this->list->versions;
388
      $versions =& $this->list->versions;
389
    }
389
    }
390
390
391
    static $row = 0;
391
    static $row = 0;
392
    $row++;
392
    $row++;
393
   
393
   
394
    $column = 0;
394
    $column = 0;
395
   
395
   
396
    foreach ($versions as $key => $value)
396
    foreach ($versions as $key => $value)
397
    {
397
    {
398
      $column++;
398
      $column++;
399
      $id = "td$row-$column";
399
      $id = "td$row-$column";
400
      $ver = $this->versions[$key];
400
      $ver = $this->versions[$key];
401
?>
401
?>
402
          <td id="<?php echo $id; ?>"<?php
402
          <td id="<?php echo $id; ?>"<?php
403
            echo $this->getAssumed($ver) . $this->getTested($ver);
403
            echo $this->getAssumed($ver) . $this->getTested($ver);
404
            if (!$key)
404
            if (!$key)
405
            {
405
            {
406
              if (!empty($ver))
406
              if (!empty($ver))
407
              {
407
              {
408
                echo ' title="Test code: '
408
                echo ' title="Test code: '
409
                  . htmlspecialchars(
409
                  . htmlspecialchars(
410
                      stripslashes($ver),
410
                      stripslashes($ver),
411
                      ENT_COMPAT,
411
                      ENT_COMPAT,
412
                      FEATURES_ENCODING)
412
                      FEATURES_ENCODING)
413
                  . '"';
413
                  . '"';
414
              }
414
              }
415
              else
415
              else
416
              {
416
              {
417
                echo ' title="Not applicable: No automated test case'
417
                echo ' title="Not applicable: No automated test case'
418
                  . ' is available for this feature.  Please click'
418
                  . ' is available for this feature.  Please click'
419
                  . ' the feature code in the first column to run'
419
                  . ' the feature code in the first column to run'
420
                  . ' a manual test."';
420
                  . ' a manual test."';
421
              }
421
              }
422
            }
422
            }
423
            ?>><?php
423
            ?>><?php
424
            if ($key)
424
            if ($key)
425
            {
425
            {
426
              echo $this->getVer($ver);
426
              echo $this->getVer($ver);
427
            }
427
            }
428
            else
428
            else
429
            {
429
            {
430
              if (!empty($ver))
430
              if (!empty($ver))
431
              {
431
              {
432
                ?><script type="text/javascript">
432
                ?><script type="text/javascript">
433
  // <![CDATA[
433
  // <![CDATA[
434
  var s = test(<?php echo $ver; ?>, '<span title="Supported">+</span>',
434
  var s = test(<?php echo $ver; ?>, '<span title="Supported">+</span>',
435
    '<span title="Not supported">&#8722;</span>');
435
    '<span title="Not supported">&#8722;</span>');
436
  tryThis("document.write(s);",
436
  tryThis("document.write(s);",
437
          "document.getElementById('<?php echo $id; ?>').appendChild("
437
          "document.getElementById('<?php echo $id; ?>').appendChild("
438
          + "document.createTextNode(s));");
438
          + "document.createTextNode(s));");
439
  // ]]>
439
  // ]]>
440
</script><?php
440
</script><?php
441
              }
441
              }
442
              else
442
              else
443
              {
443
              {
444
                echo '<abbr>N/A</abbr>';
444
                echo '<abbr>N/A</abbr>';
445
              }
445
              }
446
            }
446
            }
447
            ?></td>
447
            ?></td>
448
<?php
448
<?php
449
    }
449
    }
450
?>
450
?>
451
        </tr>
451
        </tr>
452
<?php
452
<?php
453
  }
453
  }
454
}
454
}
455
 
455
 
456
?>
456
?>
457
 
457