/**
  * Constructor
  * @param  array $arguments Associative array of application settings
  */
 public function __construct($arguments = null, $function = null)
 {
     if (ini_get('xdebug.max_nesting_level')) {
         ini_set('xdebug.max_nesting_level', 200);
     }
     if (!isset($_SESSION["runner"]) && is_array($arguments)) {
         Routerunner::setRunnerParams($arguments);
     }
     if (!self::$loaded) {
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseRunner.php';
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseModel.php';
         require 'BaseClasses' . DIRECTORY_SEPARATOR . 'BaseBootstrap.php';
         require 'Tunnel.php';
         require 'Slim' . DIRECTORY_SEPARATOR . 'Slim.php';
         require 'Slim' . DIRECTORY_SEPARATOR . 'RunnerSlim.php';
         \Slim\RunnerSlim::registerAutoloader();
         require 'SlimView.php';
         require_once 'phpquery' . DIRECTORY_SEPARATOR . 'phpQuery.php';
     }
     self::$loaded = true;
     if (isset($arguments) && is_array($arguments)) {
         $this->container['settings'] = array_merge(static::getDefaultSettings(), $arguments);
     } else {
         $this->container['settings'] = static::getDefaultSettings();
     }
     if (isset($_SESSION["routerunner-config"])) {
         $this->container['settings'] = array_merge($_SESSION["routerunner-config"], $this->container['settings']);
     }
     if (isset($this->settings['DOCUMENT_ROOT'])) {
         $site_root = $this->settings['DOCUMENT_ROOT'];
         if (substr($site_root, -1) !== DIRECTORY_SEPARATOR) {
             $site_root .= DIRECTORY_SEPARATOR;
         }
     } else {
         $site_root = rtrim(isset($_SERVER["DOCUMENT_ROOT"]) ? $_SERVER["DOCUMENT_ROOT"] : $this->settings['DOCUMENT_ROOT'], '/\\') . DIRECTORY_SEPARATOR . $this->settings['SITEROOT'];
         if (substr($site_root, -1) !== DIRECTORY_SEPARATOR) {
             $site_root .= DIRECTORY_SEPARATOR;
         }
     }
     $this->container['settings']['SITEROOT'] = $site_root;
     if (!function_exists("backend_mode")) {
         require $site_root . 'runner-config.php';
     }
     Routerunner::$static = $this;
     \Routerunner\Db::initialize($this->settings);
     new \Routerunner\Helper($this);
     \Routerunner\Routerunner::$slim = new \Slim\RunnerSlim(array('view' => new \Routerunner\CustomView(), 'templates.path' => \Routerunner\Helper::$scaffold_class));
     \Routerunner\Routerunner::$slim->notFound(function () {
         return false;
     });
     $method = "get";
     $resource = "/";
     if (!isset($arguments["bootstrap"]) || $arguments["bootstrap"] !== false) {
         \Routerunner\Bootstrap::initialize($this->settings, false);
         $method = \Routerunner\Bootstrap::getMethod();
         $resource = \Routerunner\Bootstrap::getResource();
     }
     if (isset($arguments["method"])) {
         $method = $arguments["method"];
     }
     if (isset($arguments["resource"])) {
         $resource = $arguments["resource"];
     }
     if ($method == "head") {
         $method = "get";
     }
     $routerunner_object = $this;
     \Routerunner\Config::custom_config($this->container['settings']);
     \runner::config("notFound", false);
     if (\Routerunner\Bootstrap::$component) {
         return false;
         exit;
     }
     if (isset($arguments) && isset($function) && !is_string($function) && is_callable($function) && \Routerunner\Routerunner::$slim->now('redirect_url')) {
         $arguments["skip_redirect"] = true;
         $arguments["skip_route"] = true;
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function, function () {
             if (\Routerunner\Routerunner::$slim->now('redirect_url')) {
                 \Routerunner\Routerunner::$slim->redirect(\Routerunner\Routerunner::$slim->now('redirect_url'));
             }
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (isset($arguments) && isset($function) && !is_string($function) && is_callable($function)) {
         $arguments["skip_redirect"] = true;
         $arguments["skip_route"] = true;
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function);
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (isset($arguments) && is_array($arguments) && isset($arguments['root'])) {
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } elseif (!is_string($arguments) && is_callable($arguments)) {
         $function = $arguments;
         $arguments = array("skip_redirect" => true, "skip_route" => true);
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         }, $function, function () {
             if (\Routerunner\Routerunner::$slim->now('redirect_url')) {
                 $this->redirect(\Routerunner\Routerunner::$slim->now('redirect_url'));
             }
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->run();
     } else {
         $arguments = array("skip_redirect" => true, "skip_route" => true);
         \Routerunner\Routerunner::$slim->{$method}($resource, function () use($routerunner_object, $arguments) {
             $this->middleware($routerunner_object, $arguments);
         });
         \Routerunner\Routerunner::$slim->notFound(function () use($routerunner_object, $arguments) {
             \runner::config("notFound", true);
             $this->middleware($routerunner_object, $arguments);
         });
     }
 }