Subversion Repositories PHPX

Rev

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

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