public function handle(EventInterface $event) { $logger = Application::instance()->get('Logger'); $log = new Log(); $log->log = $logger->getLogString(); $log->created_at = date('Y-m-d H:i:s'); $log->save(); }
/** * returns a string with currency formatted accordingly to locale settings * @param string $value * @param string $decimals * @param string $currencyCode * @return string */ public static function currency($value, $decimals = 2, $currencyCode = null) { $app = Application::instance(); $currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency'); $nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY); $nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals); return $nf->formatCurrency($value, $currencyCode); }
public function handle(EventInterface $event) { $app = Application::instance(); // TODO: render 404 error template // TODO: log request url? $responseStr = '<h2>Page not found!</h2>'; $response = $app->get('Response'); $response->setContent($responseStr); $response->setStatusCode(404); }
public function handle(EventInterface $event) { $app = Application::instance(); $log = $app->get('Logger')->getLogString(); if ($log !== '') { $filePath = 'logs/' . date('Y_m') . '.txt'; $fileSystem = $app->get('Filesystem'); if ($fileSystem->has($filePath)) { $log .= $fileSystem->read($filePath); } $fileSystem->put($filePath, $log); } }
public function handle(EventInterface $event, $errorNum = null, $e = null) { $app = Application::instance(); $app->get('Logger')->fatal(PHP_EOL . $e->getMessage() . PHP_EOL . $e->getTraceAsString()); if ($app->environment === 'development') { $app->get('Whoops')->handleException($e); } else { // TODO: render a error template $responseStr = "<h2>Exception:</h2> <p>" . $e->getMessage() . '</p><p>' . $e->getTraceAsString() . '</p>'; $response = $app->get('Response'); $response->setContent($responseStr); $response->setStatusCode(500); } }