77 public static function init() {
78 self::$constants = get_defined_constants(
true);
87 self::$saveCacheLoad =
false;
89 self::$cacheLoad->get(self::$loadFiles, array(
92 'request'=>array(
'uri'=>
false,
'meth'=>array()),
101 if (self::$saveCacheLoad)
102 self::$cacheLoad->save();
113 public static function loadCfg($className, $searchParent=
true) {
114 if (!array_key_exists($className, self::$loadedCfg)) {
115 self::$loadedCfg[$className] = array();
120 if ($parent = $ref->getParentClass())
121 self::mergeCfg(self::$loadedCfg[$className], self::loadCfg($parent->getName()));
124 if (count($implements = $ref->getInterfaces()) > 0)
125 foreach($implements as $imp)
126 self::mergeCfg(self::$loadedCfg[$className], self::loadCfg($imp->getName()));
136 if (!empty($listCfg))
137 foreach($listCfg as $lc) {
140 self::mergeCfg(self::$loadedCfg[$className],
$cfg, $className);
144 self::removeKeepUnique(self::$loadedCfg[$className]);
146 return self::$loadedCfg[$className];
156 if (!array_key_exists(REPLACECONF, $cfg)) {
157 $keepUnique = array_key_exists(KEEPUNIQUE, $prm);
158 foreach($cfg as $k=>&$v) {
159 if (is_numeric($k) && !$keepUnique) {
161 }
else if (is_array($v) && array_key_exists($k, $prm) && is_array($prm[$k]))
162 self::mergeCfg($prm[$k], $v);
167 unset($cfg[REPLACECONF]);
178 unset($prm[KEEPUNIQUE]);
179 foreach($prm as &$v) {
181 self::removeKeepUnique($v);
192 public static function get($className, array
$cfg = array()) {
193 if (self::$cfg && $tmp = self::$cfg->getInArray(
'classAlias', $className))
195 self::load($className);
197 if ($ref->rebuild($className)) {
198 $prm = self::loadCfg($className);
199 self::mergeCfg($prm, $cfg);
200 $inst = $ref->newInstanceCfg(
new config($prm));
203 throw new nException(
'Factory - load: Unable to bluid '.$className.
'.');
213 public static function getHelper($className, array $cfg = array()) {
214 return self::get(
'helper_'.$className, $cfg);
227 public static function getModule($name, array $cfg=array(), &$scaffold =
false, $allowScaffold=
true) {
228 $className =
'module_'.$name.
'_controller';
229 if (!self::isCreable($className)) {
230 if ($allowScaffold && in_array($name,
db::getInstance()->getTables())) {
231 $className = self::$cfg->scaffoldController;
232 $cfg[
'name'] = $name;
237 return self::get($className, $cfg);
247 public static function load($className) {
248 if (!class_exists($className) && !in_array($className, self::$loadedClass)) {
249 if (!array_key_exists($className, self::$loadFiles)) {
252 self::$loadFiles[$className] = array($file);
253 self::$saveCacheLoad =
true;
254 self::$loadedClass[] = $className;
256 if (defined(
'RUNKIT_VERSION')) {
263 if (!empty($filesExtend)) {
264 self::$loadFiles[$className][1] = $filesExtend;
265 foreach($filesExtend as $fe)
270 if (self::$throwOnLoad)
271 throw new nException(
'Factory - load: Unable to find the file for '.$className.
'.');
276 require(self::$loadFiles[$className][0]);
277 self::$loadedClass[] = $className;
278 if (defined(
'RUNKIT_VERSION') && array_key_exists(1, self::$loadFiles[$className])) {
279 foreach(self::$loadFiles[$className][1] as $fe)
static getModule($name, array $cfg=array(), &$scaffold=false, $allowScaffold=true)
static getInstance(array $cfg=array())
static getGlobalCfg($name)
static getHelper($className, array $cfg=array())
static removeKeepUnique(array &$prm)
static loadCfg($className, $searchParent=true)
static mergeCfg(array &$prm, array $cfg)
static isCreable($className)
static getInstance($cfg=null)