r22997 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22996‎ | r22997 | r22998 >
Date:01:26, 15 June 2007
Author:kim
Status:old
Tags:
Comment:
Slightly dirty cheat to assign a valid type to all ArrayRecords

now that we know the type, we can make methods to deal
with each type...
OR we can actually link the database schema (by using the structure somehow)
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSet.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -107,7 +107,9 @@
108108 $this->possiblySynonymousRelationTypeId,
109109 $this->viewQueryTransactionInformation
110110 );
111 - return $dmModel->getRecord();
 111+ $record=$dmModel->getRecord();
 112+ $record->finish("DefinedMeaning");
 113+ return $record;
112114 }
113115
114116 protected function save($referenceTransaction) {
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
@@ -10,6 +10,8 @@
1111 public abstract function getKey();
1212 public abstract function getRecordCount();
1313 public abstract function getRecord($index);
 14+ protected $type=null;
 15+ protected $records;
1416 # public function save(); # <- we first need to implement, then uncomment
1517 /**
1618 * @return carriage return separated list of values
@@ -20,7 +22,8 @@
2123
2224 public function tostring_indent($depth=0,$key="",$myname="RecordSet") {
2325 $rv="\n".str_pad("",$depth*8);
24 - $rv.="$key:$myname {";
 26+ $type=$this->type;
 27+ $rv.="$key:$myname(... $type) {";
2528 $rv2=$rv;
2629 foreach ($this->records as $value) {
2730 $rv=$rv2;
@@ -39,8 +42,38 @@
4043
4144 return $rv;
4245 }
 46+
 47+ public function getType(){
 48+ return $this->type;
 49+ }
4350
 51+ public function setType($type) {
 52+ $this->type=$type;
 53+ }
4454
 55+ /**only setType if it wasn't set yet
 56+ * @param the type you would like to suggest
 57+ * @returns the type this arrayset finally got
 58+ */
 59+ public function suggestType($type) {
 60+ if(is_null($this->type))
 61+ $this->setType($type);
 62+ return $this->getType();
 63+ }
 64+
 65+ public function finish($type) {
 66+ $type=$this->suggestType($type);
 67+
 68+
 69+ foreach ($this->records as $key=>$value) {
 70+ $methods=get_class_methods(get_class($value));
 71+ if (!is_null($methods)) {
 72+ if (in_array("finish",$methods)) {
 73+ $value->finish($this->type);
 74+ }
 75+ }
 76+ }
 77+ }
4578 }
4679
4780 class ArrayRecordSet extends RecordSet {
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -11,6 +11,7 @@
1212 class ArrayRecord implements Record {
1313 protected $structure;
1414 protected $values = array();
 15+ protected $type = null;
1516
1617 public function __construct($structure) {
1718 $this->structure = $structure;
@@ -35,6 +36,36 @@
3637 $this->values[$attribute->id] = $value;
3738 }
3839
 40+ public function getType() {
 41+ return $this->type;
 42+ }
 43+
 44+ public function setType($type) {
 45+ $this->type=$type;
 46+ }
 47+
 48+ /**only setType if it wasn't set yet.
 49+ *@param $type the type to set
 50+ *@return the type that is actually used now.
 51+ */
 52+ public function suggestType($type) {
 53+ if(is_null($this->type))
 54+ $this->setType($type);
 55+ return $this->getType();
 56+ }
 57+
 58+ public function finish($type) {
 59+ $type=$this->suggestType($type);
 60+
 61+ foreach ($this->values as $key=>$value) {
 62+ $methods=get_class_methods(get_class($value));
 63+ if (!is_null($methods)) {
 64+ if (in_array("finish",$methods)) {
 65+ $value->finish($key);
 66+ }
 67+ }
 68+ }
 69+ }
3970 /**
4071 *
4172 * @param $values Array to write into the record, by order of the structure
@@ -64,7 +95,8 @@
6596
6697 public function tostring_indent($depth=0,$key="") {
6798 $rv="\n".str_pad("",$depth*8);
68 - $rv.="$key:Record {";
 99+ $type=$this->type;
 100+ $rv.="$key:ArrayRecord(..., $type) {";
69101 $rv2=$rv;
70102 foreach ($this->values as $key=>$value) {
71103 $rv=$rv2;
@@ -73,8 +105,6 @@
74106 if (!is_null($methods)) {
75107 if (in_array("tostring_indent",$methods)) {
76108 $repr=$value->tostring_indent($depth+1,$key);
77 -
78 -
79109 }
80110 }
81111 $rv.=$repr;

Status & tagging log