public $module;\r
public $pager;\r
public $strings;\r
+ public $basepath;\r
public $path;\r
public $hooks;\r
public $timezone;\r
\r
/**\r
* @brief App constructor.\r
+ *\r
+ * @param string $basepath Path to the app base folder\r
*/\r
- function __construct() {\r
+ function __construct($basepath) {\r
\r
global $default_timezone;\r
\r
\r
startup();\r
\r
- set_include_path(\r
- get_include_path() . PATH_SEPARATOR\r
- . 'include' . PATH_SEPARATOR\r
- . 'library' . PATH_SEPARATOR\r
- . 'library/langdet' . PATH_SEPARATOR\r
- . '.');\r
-\r
$this->scheme = 'http';\r
\r
if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||\r
$this->hostname = $hostname;\r
}\r
\r
+ if (! static::directory_usable($basepath)) {\r
+ throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');\r
+ }\r
+\r
+ $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);\r
+\r
+ set_include_path(\r
+ get_include_path() . PATH_SEPARATOR\r
+ . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR\r
+ . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR\r
+ . $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR\r
+ . $this->basepath);\r
+\r
+\r
if (is_array($_SERVER['argv']) && $_SERVER['argc'] > 1 && substr(end($_SERVER['argv']), 0, 4) == 'http') {\r
$this->set_baseurl(array_pop($_SERVER['argv']));\r
$_SERVER['argc'] --;\r
self::$a = $this;\r
}\r
\r
+ /**\r
+ * @brief Returns the base filesystem path of the App\r
+ *\r
+ * It first checks for the internal variable, then for DOCUMENT_ROOT and\r
+ * finally for PWD\r
+ *\r
+ * @return string\r
+ */\r
public static function get_basepath() {\r
- $basepath = get_config('system', 'basepath');\r
+ if (isset($this)) {\r
+ $basepath = $this->basepath;\r
+ }\r
\r
- if ($basepath == '') {\r
- $basepath = dirname(__FILE__);\r
+ if (! $basepath) {\r
+ $basepath = Config::get('system', 'basepath');\r
}\r
\r
- if ($basepath == '') {\r
+ if (! $basepath && x($_SERVER, 'DOCUMENT_ROOT')) {\r
$basepath = $_SERVER['DOCUMENT_ROOT'];\r
}\r
\r
- if ($basepath == '') {\r
+ if (! $basepath && x($_SERVER, 'PWD')) {\r
$basepath = $_SERVER['PWD'];\r
}\r
\r
return;\r
}\r
\r
- if (get_config('system', 'proc_windows')) {\r
- $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));\r
+ if (Config::get('system', 'proc_windows')) {\r
+ $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());\r
} else {\r
- $resource = proc_open($cmdline . ' &', array(), $foo, dirname(__FILE__));\r
+ $resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());\r
}\r
if (!is_resource($resource)) {\r
logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);\r