nyroFwk  0.2
nyro.class.php
Go to the documentation of this file.
1 <?php
11 final class nyro {
12 
18  private static $cfg;
19 
23  private function __construct() {}
24 
28  private static function init() {
29  if (!self::$cfg) {
30  factory::init();
31  if (DEV) {
32  debug::timer('nyro');
33  debug::timer('nyroProcess');
34  }
35  request::init();
36  self::$cfg = new config(factory::loadCfg(__CLASS__));
37  file::init();
39  }
40  }
41 
45  public static function main() {
46 
47  define('NYROVERSION', '0.2');
48 
49  $globalContent = null;
50  $globalVars = null;
51  $cacheInst = null;
52  $cacheInstVars = null;
53 
54  try {
55  self::init();
56 
57  $resp = response::getInstance();
58  self::$cfg->overload(__CLASS__.'Response');
59 
60  if (self::$cfg->globalCache && !request::isPost() && count($_GET) == 0 && $resp->canGlobalCache()) {
61  $prm = is_array(self::$cfg->globalCache) ? self::$cfg->globalCache : array();
62  $cacheInst = cache::getInstance(array_merge(array('serialize'=>false), $prm));
63  $id = str_replace('/', '._.', '/'.request::get('request')).(request::isAjax() ? '-ajax' : '');
64  $cacheInst->get($globalContent, array(
65  'id'=>$id
66  ));
67  $cacheInstVars = cache::getInstance(array_merge(array('serialize'=>true), $prm));
68  $cacheInstVars->get($globalVars, array(
69  'id'=>$id.'-vars'
70  ));
71  }
72  if (is_null($globalContent)) {
74  if (DEV) {
75  debug::timer('nyroProcess');
76  debug::timer('nyroRender');
77  }
78  $resp->setContent(request::publishModule());
79  }
80  } catch (module_exception $e) {
81  session::setFlash('nyroError', 'MODULE or ACTION NOT FOUND<br />'.self::handleError($e));
82  $resp->error(null, 404);
83  } catch (nException $e) {
84  session::setFlash('nyroError', self::handleError($e));
85  $resp->error(null, 500);
86  } catch (PDOException $e) {
87  session::setFlash('nyroError', self::handleError($e));
88  $resp->error(null, 500);
89  } catch (Exception $e) {
90  session::setFlash('nyroError', self::handleError($e));
91  $resp->error(null, 500);
92  }
93 
94  try {
96 
97  if ($cacheInst) {
98  if ($globalContent) {
99  $resp->setVarsFromGlobalCache($globalVars);
100  echo $globalContent;
101  } else {
102  $globalVars = $resp->getVarsForGlobalCache();
103  $globalContent = $resp->send();
104  $cacheInst->save();
105  $cacheInstVars->save();
106  echo $globalContent;
107  }
108  } else {
109  echo $resp->send();
110  }
111  } catch (Exception $e) {
112  echo debug::trace($e);
113  }
114  }
115 
122  public static function getGlobalCfg($name) {
123  if (self::$cfg && self::$cfg->check($name))
124  return self::$cfg->get($name);
125  return array();
126  }
127 
133  public static function getCfg() {
134  return self::$cfg;
135  }
136 
143  private static function handleError(Exception $err) {
144  return debug::trace($err, DEV? 2 : 0);
145  }
146 
147 }
static init()
static get($get=null)
__construct()
Definition: nyro.class.php:23
static init()
static getInstance(array $cfg=array())
Definition: cache.class.php:30
static main()
Definition: nyro.class.php:45
static getCfg()
Definition: nyro.class.php:133
static getGlobalCfg($name)
Definition: nyro.class.php:122
static setFlash($name, $val=null)
static init()
Definition: nyro.class.php:28
static execModule()
static timer($name=null)
static init()
Definition: file.class.php:51
static $cfg
Definition: nyro.class.php:18
static getInstance()
static publishModule()
static loadCfg($className, $searchParent=true)
static saveCache()
static isPost()
static handleError(Exception $err)
Definition: nyro.class.php:143
static initFlash()
static trace($obj, $printExit=false)
Definition: debug.class.php:54
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13