Highway to PSR2
[openemr.git] / portal / patient / _global_config.php
blobce71b58fb5e4c26e1bf4c16644e1fb56bad6b1bb
1 <?php
2 /**
3 * @package Adserv
5 * GLOBAL CONFIGURATION
7 * This file defines a singleton class that is used for dependency injection
8 * into the framework dispatcher.
10 * For the most part the settings here shouldn't be changed. The static
11 * properties can be changed in either _app_config.php or _machine_config.php
12 * depending on whether the setting is application-wide or machine-specific
14 * From phreeze package
15 * @license http://www.gnu.org/copyleft/lesser.html LGPL
19 /**
20 * GlobalConfig is a singleton containing the global variables.
21 * In general settings should not be changed in this file and should instead
22 * be made in either _app_config.php or _machine_config.php
24 * For unit testing this object can be swapped out with another object entirely
25 * to allow for mock data, mockput, etc as needed
27 * @package Portal
28 * @author sjpadgett@gmail.com
30 class GlobalConfig
32 /** @var set to true to send debug info to the browser */
33 public static $DEBUG_MODE = false;
35 public static $PORTAL = false;
36 /** @var default action is the controller.method fired when no route is specified */
37 public static $DEFAULT_ACTION = "Provider.Home";
39 /** @var routemap is an array of patterns and routes */
40 public static $ROUTE_MAP;
42 /** @var specify the template render engine (Smarty, Savant, PHP) */
43 public static $TEMPLATE_ENGINE = 'SavantRenderEngine';
45 /** @var template path is the physical location of view template files */
46 public static $TEMPLATE_PATH;
48 /** @var template cache path is the physical location where templates can be cached */
49 public static $TEMPLATE_CACHE_PATH;
51 /** @var app root is the root directory of the application */
52 public static $APP_ROOT;
54 /** @var root url of the application */
55 public static $ROOT_URL;
57 /** @var ConnectionSetting object containign settings for the DB connection **/
58 public static $CONNECTION_SETTING;
60 /** @var Setting to true will convert all NULL values to an empty string (set to false with caution!) **/
61 public static $CONVERT_NULL_TO_EMPTYSTRING = true;
63 /** @var ICache (optional) object for level 2 caching (for example memcached) **/
64 public static $LEVEL_2_CACHE;
66 /** @var string if level 2 cache is specified, a temp path for writing files */
67 public static $LEVEL_2_CACHE_TEMP_PATH;
69 /** @var int if level 2 cache is specified, the timeout in seconds*/
70 public static $LEVEL_2_CACHE_TIMEOUT = 15;
72 private static $INSTANCE;
73 private static $IS_INITIALIZED = false;
75 private $context;
76 private $router;
77 private $phreezer;
78 private $render_engine;
80 /** prevents external construction */
81 private function __construct()
85 /** prevents external cloning */
86 private function __clone()
90 /**
91 * Initialize the GlobalConfig object
93 static function Init()
95 if (!self::$IS_INITIALIZED) {
96 require_once 'verysimple/HTTP/RequestUtil.php';
97 RequestUtil::NormalizeUrlRewrite();
99 require_once 'verysimple/Phreeze/Controller.php';
100 Controller::$SmartyViewPrefix = '';
101 Controller::$DefaultRedirectMode = 'header';
103 self::$IS_INITIALIZED = true;
108 * Returns an instance of the GlobalConfig singleton
109 * @return GlobalConfig
111 static function GetInstance()
113 if (!self::$IS_INITIALIZED) {
114 self::Init();
117 if (!self::$INSTANCE instanceof self) {
118 self::$INSTANCE = new self;
121 return self::$INSTANCE;
125 * Returns the context, used for storing session information
126 * @return Context
128 function GetContext()
130 if ($this->context == null) {
133 return $this->context;
137 * Returns a URL Writer used to parse/generate URLs
138 * @return UrlWriter
140 function GetRouter()
142 if ($this->router == null) {
143 require_once("verysimple/Phreeze/GenericRouter.php");
144 $this->router = new GenericRouter(self::$ROOT_URL, self::GetDefaultAction(), self::$ROUTE_MAP);
147 return $this->router;
152 * Returns the requested action requested by the user
153 * @return string
155 function GetAction()
157 list($controller,$method) = $this->GetRouter()->GetRoute();
158 return $controller.'.'.$method;
162 * Returns the default action if none is specified by the user
163 * @return string
165 function GetDefaultAction()
167 return self::$DEFAULT_ACTION;
171 * Returns the Phreezer persistance layer
172 * @return Phreezer
174 function GetPhreezer()
176 if ($this->phreezer == null) {
177 if (!self::$CONVERT_NULL_TO_EMPTYSTRING) {
178 require_once("verysimple/DB/DatabaseConfig.php");
179 DatabaseConfig::$CONVERT_NULL_TO_EMPTYSTRING = false;
182 if (self::$DEBUG_MODE) {
183 require_once("verysimple/Phreeze/ObserveToSmarty.php");
184 $observer = new ObserveToSmarty($this->GetRenderEngine());
185 $this->phreezer = new Phreezer(self::$CONNECTION_SETTING, $observer);
186 } else {
187 $this->phreezer = new Phreezer(self::$CONNECTION_SETTING);
190 if (self::$LEVEL_2_CACHE) {
191 $this->phreezer->SetLevel2CacheProvider(self::$LEVEL_2_CACHE, self::$LEVEL_2_CACHE_TEMP_PATH);
192 $this->phreezer->ValueCacheTimeout = self::$LEVEL_2_CACHE_TIMEOUT;
196 return $this->phreezer;
200 * @return IRenderEngine
202 function GetRenderEngine()
204 if ($this->render_engine == null) {
205 $engine_class = self::$TEMPLATE_ENGINE;
206 if (!class_exists($engine_class)) {
207 require_once 'verysimple/Phreeze/'. $engine_class . '.php';
210 $this->render_engine = new $engine_class(self::$TEMPLATE_PATH, self::$TEMPLATE_CACHE_PATH);
211 $this->render_engine->assign("ROOT_URL", self::$ROOT_URL);
212 $this->render_engine->assign("PHREEZE_VERSION", Phreezer::$Version);
213 $this->render_engine->assign("PHREEZE_PHAR", Phreezer::PharPath());
216 return $this->render_engine;