- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
function &GetObject($cls, $p=null, $flags=0)
{ //HIDE($objects,$i,$ext,$n,$v)
static $objects;
if (is_array($cls)) {
$i = null;
foreach($cls as $n=>$v) $i->$n = $v;
$result = &$i;
return $result;
}
if (!($flags&O_NEW) && isset($objects[$cls])) return $objects[$cls];
$ext = new WExtern($cls, 'c');
if (!($flags&O_NEW) && isset($objects[$i=$ext->Id()])) return $objects[$i];
if ($flags&O_INSTANCE) {$x = null; $result = &$x; return $result;}
if (!$ext->Exists()) $ext->Prepare();
if (($flags&O_NOERROR) && !class_exists($ext->c)) {
$co = $ext->c;
$cc = $co{0}.'B'.substr($co,1);
if (($flags&O_NOERROR) && !class_exists($cc)) {
$i = false;
return $i;
} else {
$ext->c = $cc;
}
}
if (!class_exists($ext->c)) {
$co = $ext->c;
$cc = $co{0}.'B'.substr($co,1);
if (!class_exists($cc)) {
$i = false;
return $i;
} else {
$ext->c = $cc;
}
}
$c = $ext->c;
$i = new $c;
if (isset($ext->I) && $ext->I) $i->_I = reset($ext->I); // Instance ID
if (isset($ext->A) && $ext->A) $i->_A = $ext->A; // Alias ID
if (!($flags&O_NEW)) {
$objects[$ext->Id()] = &$i;
if ($ext->Id()!=$cls) $objects[$cls] = &$i;
}
$options = &WConfig::Get('OPTIONS');
if (/*is_a($i, 'wobject')*/ $i instanceof wobject && $options) {
$o = $options;
$c = get_class($i);
do{
$c = strtolower($c);
if (isset($o[$c])) {
$i->o = array_merge($o[$c], isset($i->o) ?$i->o :array());
}
}while($c=get_parent_class($c));
if (isset($ext->A) && isset($o[$ext->A])) $i->o = array_merge(isset($i->o) ?$i->o :array(), $o[$ext->A]);
if ($ext->I && isset($o[$ext->Id()])) $i->o = array_merge(isset($i->o) ?$i->o :array(), $o[$o[$ext->Id()]]);
}
if (is_object($p)) {
if (isset($p->o)) $i->o = array_merge(isset($i->o) ?$i->o :array(), $p->o);
$p = isset($p->c) ? $p->c : null;
}
if (method_exists($i,'Create') && $p!==false) {
call_user_func_array(array(&$i,'Create'), is_array($p) ?$p : (isset($p) ? array($p) : array()));
}
return $i;
}