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