<?php /** * Created by PhpStorm. * User: csibi * Date: 2013.11.15. * Time: 14:52 */ namespace Routerunner; class Config { public static $defaults = array('mode' => 'production', 'root' => 'standard', 'scaffold.version' => null, 'debug' => true, 'log.writer' => '\\Routerunner\\Log', 'log.level' => \Slim\Log::DEBUG, 'log.enabled' => true, 'scaffold' => 'scaffold', 'SITE' => '', 'SITENAME' => '', 'SITEROOT' => '', 'BASE' => '', 'ROUTERUNNER_ROOT' => 'RouterunnerCMS/', 'ROUTERUNNER_BASE' => 'RouterunnerCMS/', 'DB_HOST' => '', 'DB_NAME' => '', 'DB_USER' => '', 'DB_PASS' => '', 'DB_PREFIX' => '_', 'PREFIX' => '_', 'DB_CHARSET' => 'utf8', 'LANG' => 'en', 'Mail.Host' => '', 'Mail.SMTPAuth' => true, 'Mail.Port' => 465, 'Mail.Username' => '', 'Mail.Password' => '', 'Mail.SMTPSecure' => 'tls', 'Mail.From' => '', 'Mail.FromName' => '', 'Mail.WordWrap' => 50, 'Mail.CharSet' => 'UTF-8', 'Mail.Subject' => '', 'User.UserFlashVar' => 'member', 'User.UserArrayToTranslate' => array('nev' => 'name'), 'User.RememberMeVar' => 'rememberme', 'User.DefaultGroup' => 1, 'User.DefaultUniqueScope' => null, 'User.DefaultUniqueAuth' => null, 'User.TokenSet' => array('email', 'HTTP_USER_AGENT'), 'User.TokenExpire' => null, 'User.TokenUserData' => array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER'), 'User.TokenSession' => 'token', 'User.TokenCookie' => 'cookie', 'User.TokenCookieExpire' => 7776000); public static function custom_config($custom) { self::$defaults = array_merge(self::$defaults, $custom); } } if (isset($_SESSION["runner_config"]) && is_array($_SESSION["runner_config"])) { \Routerunner\Config::custom_config($_SESSION["runner_config"]); }
/** * 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); }); } }