Subversion Repositories PHPX

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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