Add basepath to App

This commit is contained in:
Hypolite Petovan 2017-05-02 22:42:42 -04:00
parent 3437e73ae4
commit 569cd459ec
10 changed files with 49 additions and 28 deletions

View File

@ -49,8 +49,9 @@ require_once("boot.php");
global $a, $db; global $a, $db;
if (is_null($a)) if (is_null($a)) {
$a = new App; $a = new App(dirname(__DIR__));
}
if (is_null($db)) { if (is_null($db)) {
@include(".htconfig.php"); @include(".htconfig.php");

View File

@ -12,7 +12,7 @@ function cli_startup() {
global $a, $db; global $a, $db;
if (is_null($a)) { if (is_null($a)) {
$a = new App; $a = new App(dirname(__DIR__));
} }
if (is_null($db)) { if (is_null($db)) {

View File

@ -1736,7 +1736,7 @@ function dbstructure_run(&$argv, &$argc) {
global $a, $db; global $a, $db;
if (is_null($a)) { if (is_null($a)) {
$a = new App; $a = new App(dirname(__DIR__));
} }
if (is_null($db)) { if (is_null($db)) {

View File

@ -19,8 +19,8 @@ require_once("boot.php");
function poller_run($argv, $argc){ function poller_run($argv, $argc){
global $a, $db; global $a, $db;
if(is_null($a)) { if (is_null($a)) {
$a = new App; $a = new App(dirname(__DIR__));
} }
if(is_null($db)) { if(is_null($db)) {

View File

@ -10,7 +10,7 @@ function shadowupdate_run(&$argv, &$argc){
global $a, $db; global $a, $db;
if (is_null($a)) { if (is_null($a)) {
$a = new App; $a = new App(dirname(__DIR__));
} }
if (is_null($db)) { if (is_null($db)) {

View File

@ -19,7 +19,7 @@ use Friendica\Core\Config;
require_once 'boot.php'; require_once 'boot.php';
require_once 'object/BaseObject.php'; require_once 'object/BaseObject.php';
$a = new App; $a = new App(__DIR__);
BaseObject::set_app($a); BaseObject::set_app($a);
// We assume that the index.php is called by a frontend process // We assume that the index.php is called by a frontend process

View File

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

View File

@ -11,7 +11,7 @@ use Friendica\App;
*/ */
require_once("boot.php"); require_once("boot.php");
$a = new App; $a = new App(dirname(__DIR__));
@include(".htconfig.php"); @include(".htconfig.php");
$lang = get_browser_language(); $lang = get_browser_language();

View File

@ -5,7 +5,7 @@ use Friendica\Core\Config;
require_once("boot.php"); require_once("boot.php");
$a = new App; $a = new App(dirname(__DIR__));
@include(".htconfig.php"); @include(".htconfig.php");
$lang = get_browser_language(); $lang = get_browser_language();

View File

@ -12,7 +12,7 @@ ini_set('log_errors', '0');
include 'boot.php'; include 'boot.php';
$a = new App(); $a = new App(dirname(__DIR__));
if (x($a->config, 'php_path')) { if (x($a->config, 'php_path')) {
$phpath = $a->config['php_path']; $phpath = $a->config['php_path'];