-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMHelper.php
69 lines (57 loc) · 1.38 KB
/
MHelper.php
1
2
3
4
5
6
7
8
9
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
<?php
/**
* Класс-хелпер
*
* <code>
* MHelper::get('Type')->method(params);
* OR
* MHelper::get()->Type->method(params);
* OR
* MHelper::Type()->method(params); // PHP 5.3+ only
* </code>
*
* @version 0.1 21.08.2011
* @author webmaxx <[email protected]>
*/
class MHelper
{
protected static $_Instance = null;
protected static $_Helpers = array();
private function __construct() {}
private function __clone() {}
public static function __callStatic($name, $arguments)
{
return self::get($name);
}
public function __get($name)
{
if (!isset(self::$_Helpers[$name])) {
$className = 'M'.ucfirst($name);
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'MHelper'.DIRECTORY_SEPARATOR.$className.'.php';
self::$_Helpers[$name] = new $className;
}
return self::$_Helpers[$name];
}
public static function get($name)
{
if (self::$_Instance === null)
self::$_Instance = new self;
return $name ? self::$_Instance->{$name} : self::$_Instance;
}
}
/**
* Базовый класс для всех классов-хелперов
*
* @version 0.1 21.08.2011
* @author webmaxx <[email protected]>
*/
abstract class MHelperBase
{
protected static $_trash = array();
protected function _functionExists($name)
{
if (!isset($this->_trash[$name]))
$this->_trash[$name] = function_exists($name);
return $this->_trash[$name];
}
}