3 * Useful globals class for Rest
6 * @link http://www.open-emr.org
7 * @author Jerry Padgett <sjpadgett@gmail.com>
8 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 // also a handy place to add utility methods
17 /** @var set to true to send debug info to the browser */
18 public static $DEBUG_MODE = false;
20 /** @var default action is the controller.method fired when no route is specified */
21 public static $DEFAULT_ACTION = "";
23 /** @var routemap is an array of patterns and routes */
24 public static $ROUTE_MAP;
26 /** @var app root is the root directory of the application */
27 public static $APP_ROOT;
29 /** @var root url of the application */
30 public static $ROOT_URL;
31 public static $REST_FULL_URL;
32 public static $VENDOR_DIR;
33 public static $webserver_root;
34 public static $web_root;
35 public static $server_document_root;
38 private static $INSTANCE;
39 private static $IS_INITIALIZED = false;
43 /** prevents external construction */
44 private function __construct()
48 /** prevents external cloning */
49 private function __clone()
54 * Initialize the RestConfig object
56 static function Init()
58 if (!self
::$IS_INITIALIZED) {
60 self
::$REST_FULL_URL = $_SERVER['REQUEST_SCHEME'] . "//" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; // @todo unsure here!
61 self
::$ROOT_URL = self
::$web_root . "/apis";
62 self
::$VENDOR_DIR = self
::$webserver_root . "/vendor";
63 self
::$IS_INITIALIZED = true;
68 * Returns an instance of the RestConfig singleton
71 static function GetInstance()
73 if (!self
::$IS_INITIALIZED) {
77 if (!self
::$INSTANCE instanceof self
) {
78 self
::$INSTANCE = new self
;
81 return self
::$INSTANCE;
85 * Returns the context, used for storing session information
90 if ($this->context
== null) {
93 return $this->context
;
97 * Basic paths when GLOBALS are not yet available.
100 static function SetPaths()
102 $isWindows = stripos(PHP_OS
, 'WIN') === 0;
103 self
::$webserver_root = dirname(__FILE__
);
105 //convert windows path separators
106 self
::$webserver_root = str_replace("\\", "/", self
::$webserver_root);
108 // Collect the apache server document root (and convert to windows slashes, if needed)
109 self
::$server_document_root = realpath($_SERVER['DOCUMENT_ROOT']);
111 //convert windows path separators
112 self
::$server_document_root = str_replace("\\", "/", self
::$server_document_root);
114 self
::$web_root = substr(self
::$webserver_root, strspn(self
::$webserver_root ^ self
::$server_document_root, "\0"));
115 // Ensure web_root starts with a path separator
116 if (preg_match("/^[^\/]/", self
::$web_root)) {
117 self
::$web_root = "/" . self
::$web_root;
121 function destroySession()
123 if (!isset($_SESSION)) {
127 if (ini_get("session.use_cookies")) {
128 $params = session_get_cookie_params();
142 // Include our routes and init routes global
144 include_once("./../_rest_routes.inc.php");