r24307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24306‎ | r24307 | r24308 >
Date:20:06, 21 July 2007
Author:kim
Status:old
Tags:
Comment:
Updated OmegaWikiAttributes to be a (semi-) singleton, will update all other files that were using a global 'till now
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -35,7 +35,7 @@
3636 $omegaWikiAttributes; // It would be even better if this was
3737 // passed to objects explicitly
3838 // but one step at a time...
39 - $omegaWikiAttributes= new OmegaWikiAttributes($viewInformation);
 39+ $omegaWikiAttributes= OmegaWikiAttributes::getInstance($viewInformation);
4040 initializeOmegaWikiAttributesOld($viewInformation); //backward compatibility, will be removed.
4141 }
4242
@@ -356,6 +356,20 @@
357357
358358
359359 class OmegaWikiAttributes {
 360+
 361+ /** pseudo-Singleton, if viewinformation changes, will construct new instance*/
 362+ static function getInstance(ViewInformation $viewInformation=null) {
 363+ static $instance=array();
 364+ if (!is_null($viewInformation)) {
 365+ if (!array_key_exists($viewInformation->hashCode(), $instance)) {
 366+ $instance["last"] = new OmegaWikiAttributes($viewInformation);
 367+ $instance[$viewInformation->hashCode()] = $instance["last"];
 368+ }
 369+ }
 370+
 371+ return $instance["last"];
 372+ }
 373+
360374 protected $attributes = array();
361375
362376 function __construct(ViewInformation $viewInformation) {

Status & tagging log