24 private $startTime =
null;
25 private $request =
null;
26 private $response =
null;
28 private $debug =
false;
30 private static $logger =
null;
31 private static $errorHandler =
null;
37 $this->startTime = microtime(
true);
38 if (
self::$logger ==
null) {
41 ob_start([
$this,
"outputHandler"]);
50 if (
self::$logger->isDebugEnabled()) {
51 $timeDiff = microtime(
true)-
$this->startTime;
52 $memory = number_format(memory_get_peak_usage()/(
1024*
1024),
2);
53 $msg =
"Time[".round($timeDiff,
2).
"s] Memory[".$memory.
"mb]";
54 if (
$this->request !=
null) {
55 $msg .=
" Request[".
$this->request->getSender().
"?".
56 $this->request->getContext().
"?".
$this->request->getAction().
"]";
58 $msg .=
" URI[".$_SERVER[
'REQUEST_URI'].
"]";
59 self::$logger->debug($msg);
72 public function initialize($defaultController='', $defaultContext='', $defaultAction='login') {
74 $this->debug = $config->getBooleanValue(
'debug',
'Application');
77 if ($config->hasSection(
'phpconfig')) {
78 $phpSettings = $config->getSection(
'phpconfig');
79 foreach ($phpSettings
as $option => $value) {
80 ini_set($option, $value);
87 $this->request->setResponse(
$this->response);
89 $this->request->initialize($defaultController, $defaultContext, $defaultAction);
96 $authUser = $principalFactory->getUser($session->getAuthUser(),
true);
97 if ($authUser && strlen($authUser->getConfig()) >
0) {
98 $config->addConfiguration($authUser->getConfig(),
true);
102 $listeners = $config->getValue(
'listeners',
'application');
103 foreach ($listeners
as $key) {
108 date_default_timezone_set($config->getValue(
'timezone',
'application'));
111 return $this->request;
122 return $this->response;
132 $logFunction =
'error';
137 self::$logger->$logFunction($exception);
143 $persistenceFacade->getTransaction()->rollback();
146 if (
$this->request) {
148 $this->request->addError($error);
149 $this->response->addError($error);
150 $this->request->setAction(
'failure');
151 $this->response->setAction(
'failure');
152 $this->response->setStatus($error->getStatusCode());
159 catch (\
Exception $ex) {
160 self::$logger->error($ex->getMessage().
"\n".$ex->getTraceAsString());
172 $error = error_get_last();
173 if ($error !==
null && (in_array($error[
'type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR]))) {
174 $errorStr = $error[
'file'].
"::".$error[
'line'].
": ".$error[
'type'].
": ".$error[
'message'];
175 self::$logger->error($errorStr);
178 header(
'HTTP/1.1 500 Internal Server Error');
182 $buffer =
"<pre>\n".$errorStr.
"\n</pre>";
185 return trim($buffer);
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.
outputHandler($buffer)
This method is run as ob_start callback.
__construct()
Constructor.
handleException(\Exception $exception)
Default exception handling method.
ApplicationException signals a general application exception.
run(Request $request)
Run the application with the given request.
static getLogger($name)
Get the logger with the given name.
static getInstance($name, $dynamicConfiguration=[])
initialize($defaultController='', $defaultContext='', $defaultAction='login')
Initialize the request.
LogManager is used to retrieve Logger instances.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
Application is the main application class, that does all the initialization.
ErrorHandler catches all php errors and transforms fatal errors into ErrorExceptions and non-fatal in...
Presentation related interfaces and classes.