25 private $_startTime = null;
26 private $_initialRequest = null;
28 private $_debug =
true;
30 private static $_logger = null;
36 $this->_startTime = microtime(
true);
37 if (self::$_logger == null) {
40 ob_start(array($this,
"outputHandler"));
49 if (self::$_logger->isDebugEnabled()) {
50 $timeDiff = microtime(
true)-$this->_startTime;
51 $memory = number_format(memory_get_peak_usage()/(1024*1024), 2);
52 $msg =
": Time[".round($timeDiff, 2).
"s] Memory[".$memory.
"mb]";
53 if ($this->_initialRequest != null) {
54 $msg .=
" Request[".$this->_initialRequest->getSender().
"?".
55 $this->_initialRequest->getContext().
"?".$this->_initialRequest->getAction().
"]";
57 $msg .=
" URI[".$_SERVER[
'REQUEST_URI'].
"]";
58 self::$_logger->debug($msg);
71 public function initialize($defaultController=
'', $defaultContext=
'', $defaultAction=
'login') {
76 $this->_initialRequest->initialize($defaultController, $defaultContext, $defaultAction);
82 $session->clearErrors();
85 $authUser = $session->getAuthUser();
86 if ($authUser && strlen($authUser->getConfig()) > 0) {
87 $config->addConfiguration($authUser->getConfig(),
true);
91 $listeners = $config->getValue(
'listeners',
'application');
92 foreach ($listeners as $key) {
97 date_default_timezone_set($config->getValue(
'timezone',
'application'));
100 return $this->_initialRequest;
121 self::$_logger->error($exception->getMessage().
"\n".$exception->getTraceAsString());
126 $persistenceFacade->getTransaction()->rollback();
129 if ($request == null) {
130 $request = $this->_initialRequest;
133 $request->setAction(
'failure');
149 $error = error_get_last();
150 if ($error !== NULL) {
151 $info =
"Error: ".$error[
'message'].
" in ".$error[
'file'].
" on line ".$error[
'line'];
152 self::$_logger->error($info);
155 if (!$this->_debug) {
156 header(
'HTTP/1.1 500 Internal Server Error');
160 return trim($buffer);
initialize($defaultController='', $defaultContext='', $defaultAction='login')
Initialize the request.
Application is the main application class, that does all the initialization.
Presentation related interfaces and classes.
static getLogger($name)
Get the logger with the given name.
static getInstance($name, $dynamicConfiguration=array())
Request holds the request values that are used as input to Controller instances.
static fromException(\Exception $ex)
Factory method for transforming an exception into an ApplicationError instance.
ErrorHandler catches all php errors and transforms fatal errors into ErrorExceptions and non-fatal in...
handleException(\Exception $exception, Request $request=null)
Default exception handling method.
outputHandler($buffer)
This method is run as ob_start callback.
__construct()
Constructor.
run(Request $request)
Run the application with the given request.