r22989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22988‎ | r22989 | r22990 >
Date:16:52, 14 June 2007
Author:kim
Status:old
Tags:
Comment:
refactored so that convertingrecordsets also should show up
(they don't, thus possibly proving that they are redundant?)
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSet.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
@@ -5,15 +5,45 @@
66 require_once('Attribute.php');
77 require_once('Record.php');
88
9 -interface RecordSet {
10 - public function getStructure();
11 - public function getKey();
12 - public function getRecordCount();
13 - public function getRecord($index);
 9+abstract class RecordSet {
 10+ public abstract function getStructure();
 11+ public abstract function getKey();
 12+ public abstract function getRecordCount();
 13+ public abstract function getRecord($index);
1414 # public function save(); # <- we first need to implement, then uncomment
 15+/**
 16+ * @return carriage return separated list of values
 17+ */
 18+ public function __tostring() {
 19+ return $this->tostring_indent();
 20+ }
 21+
 22+ public function tostring_indent($depth=0,$key="",$myname="RecordSet") {
 23+ $rv="\n".str_pad("",$depth*8);
 24+ $rv.="$key:$myname {";
 25+ $rv2=$rv;
 26+ foreach ($this->records as $value) {
 27+ $rv=$rv2;
 28+ $methods=get_class_methods(get_class($value));
 29+ if (!is_null($methods)) {
 30+ if (in_array("tostring_indent",$methods)) {
 31+ $value=$value->tostring_indent($depth+1);
 32+ }
 33+ }
 34+ $rv.="$value";
 35+
 36+ $rv2=$rv;
 37+ $rv2.=", ";
 38+ }
 39+ $rv.="}";
 40+
 41+ return $rv;
 42+ }
 43+
 44+
1545 }
1646
17 -class ArrayRecordSet implements RecordSet {
 47+class ArrayRecordSet extends RecordSet {
1848 protected $structure;
1949 protected $key;
2050 protected $records = array();
@@ -49,38 +79,14 @@
5080 public function getRecord($index) {
5181 return $this->records[$index];
5282 }
53 -
54 - /**
55 - * @return carriage return separated list of values
56 - */
57 - public function __tostring() {
58 - return $this->tostring_indent();
 83+
 84+ public function tostring_indent($depth=0,$key="",$myname="") {
 85+ return parent::tostring_indent($depth,$key,$myname."_ArrayRecordSet");
5986 }
60 -
61 - public function tostring_indent($depth=0,$key="") {
62 - $rv="\n".str_pad("",$depth*8);
63 - $rv.="$key:ArrayRecordSet {";
64 - $rv2=$rv;
65 - foreach ($this->records as $value) {
66 - $rv=$rv2;
67 - $methods=get_class_methods(get_class($value));
68 - if (!is_null($methods)) {
69 - if (in_array("tostring_indent",$methods)) {
70 - $value=$value->tostring_indent($depth+1);
71 - }
72 - }
73 - $rv.="$value";
7487
75 - $rv2=$rv;
76 - $rv2.=", ";
77 - }
78 - $rv.="}";
79 -
80 - return $rv;
81 - }
8288 }
8389
84 -class ConvertingRecordSet implements RecordSet {
 90+class ConvertingRecordSet extends RecordSet {
8591 protected $relation;
8692 protected $converters;
8793 protected $structure;
@@ -121,6 +127,10 @@
122128
123129 return new Structure($attributes);
124130 }
 131+
 132+ public function tostring_indent($depth=0,$key="",$myname="") {
 133+ return parent::tostring_indent($depth,$key,$myname."_ConvertingRecordSet");
 134+ }
125135 }
126136
127137 function getRelationAsHTMLList($relation) {

Status & tagging log