XOOPS  2.6.0
XoopsModelFactory.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Core\Kernel;
13 
16 
29 {
33  static private $handlers = array();
34 
41  public static function getInstance()
42  {
43  static $instance;
44  if (!isset($instance)) {
45  $class = __CLASS__;
46  $instance = new $class();
47  }
48  return $instance;
49  }
50 
60  public function loadHandler(XoopsPersistableObjectHandler $oHandler, $name, $args = null)
61  {
62  if (!isset(self::$handlers[$name])) {
63  $handler = null;
64  $className = '\Xoops\Core\Kernel\Model\\' . ucfirst($name);
65  @$handler = new $className();
66  if (!is_object($handler)) {
67  trigger_error('Handler ' . $className . ' not found in file ' . __FILE__, E_USER_WARNING);
68  return null;
69  }
70  self::$handlers[$name] = $handler;
71  }
72  /* @var $handler XoopsModelAbstract */
73  $handler = clone (self::$handlers[$name]);
74  $handler->setHandler($oHandler);
75  if (!empty($args) && is_array($args) && is_a($handler, 'Xoops\Core\Kernel\XoopsModelAbstract')) {
76  $handler->setVars($args);
77  }
78  return $handler;
79  }
80 }
loadHandler(XoopsPersistableObjectHandler $oHandler, $name, $args=null)