Commit f26e96a1d1facaf6ba58c629f8edeada3e51b052

Authored by Conrad Vermeulen
1 parent ed9fbd5c

KTS-2358

"php5 migration"
Updated. Removed & from &new. Added statics.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7195 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/widgets/widgetfactory.inc.php
1 1 <?php
2 2 /**
3 3 * $Id$
4   - *
  4 + *
5 5 * The contents of this file are subject to the KnowledgeTree Public
6 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 7 * compliance with the License. You may obtain a copy of the License at
8 8 * http://www.knowledgetree.com/KPL
9   - *
  9 + *
10 10 * Software distributed under the License is distributed on an "AS IS"
11 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 12 * See the License for the specific language governing rights and
... ... @@ -17,9 +17,9 @@
17 17 * (ii) the KnowledgeTree copyright notice
18 18 * in the same form as they appear in the distribution. See the License for
19 19 * requirements.
20   - *
  20 + *
21 21 * The Original Code is: KnowledgeTree Open Source
22   - *
  22 + *
23 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 24 * (Pty) Ltd, trading as KnowledgeTree.
25 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -38,13 +38,15 @@
38 38 class KTWidgetFactory {
39 39 var $widgets = array();
40 40  
41   - function &getSingleton() {
42   - if (!KTUtil::arrayGet($GLOBALS['_KT_PLUGIN'], 'oKTWidgetFactory')) {
43   - $GLOBALS['_KT_PLUGIN']['oKTWidgetFactory'] = new KTWidgetFactory;
44   - }
45   - return $GLOBALS['_KT_PLUGIN']['oKTWidgetFactory'];
  41 + static function &getSingleton () {
  42 + static $singleton=null;
  43 + if (is_null($singleton))
  44 + {
  45 + $singleton = new KTWidgetFactory();
  46 + }
  47 + return $singleton;
46 48 }
47   -
  49 +
48 50 function registerWidget($sClassname, $sNamespace, $sFilename = null) {
49 51 $this->widgets[$sNamespace] = array(
50 52 'ns' => $sNamespace,
... ... @@ -52,7 +54,7 @@ class KTWidgetFactory {
52 54 'file' => $sFilename,
53 55 );
54 56 }
55   -
  57 +
56 58 function &getWidgetByNamespace($sNamespace) {
57 59 $aInfo = KTUtil::arrayGet($this->widgets, $sNamespace);
58 60 if (empty($aInfo)) {
... ... @@ -61,30 +63,30 @@ class KTWidgetFactory {
61 63 if (!empty($aInfo['file'])) {
62 64 require_once($aInfo['file']);
63 65 }
64   -
  66 +
65 67 return new $aInfo['class'];
66   - }
67   -
  68 + }
  69 +
68 70 // this is overridden to either take a namespace or an instantiated
69 71 // class. Doing it this way allows for a consistent approach to building
70   - // forms including custom widgets.
  72 + // forms including custom widgets.
71 73 function &get($namespaceOrObject, $aConfig = null) {
72 74 if (is_string($namespaceOrObject)) {
73 75 $oWidget =& $this->getWidgetByNamespace($namespaceOrObject);
74 76 } else {
75 77 $oWidget = $namespaceOrObject;
76 78 }
77   -
  79 +
78 80 if (PEAR::isError($oWidget)) {
79 81 return $oWidget;
80 82 }
81   -
  83 +
82 84 $aConfig = (array) $aConfig; // always an array
83 85 $res = $oWidget->configure($aConfig);
84 86 if (PEAR::isError($res)) {
85 87 return $res;
86 88 }
87   -
  89 +
88 90 return $oWidget;
89 91 }
90 92 }
... ...