Add basepath to App
This commit is contained in:
parent
3437e73ae4
commit
569cd459ec
|
@ -49,8 +49,9 @@ require_once("boot.php");
|
|||
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a))
|
||||
$a = new App;
|
||||
if (is_null($a)) {
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
|
|
|
@ -12,7 +12,7 @@ function cli_startup() {
|
|||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
|
|
|
@ -1736,7 +1736,7 @@ function dbstructure_run(&$argv, &$argc) {
|
|||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
|
|
|
@ -19,8 +19,8 @@ require_once("boot.php");
|
|||
function poller_run($argv, $argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
if (is_null($a)) {
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
|
|
|
@ -10,7 +10,7 @@ function shadowupdate_run(&$argv, &$argc){
|
|||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
|
|
|
@ -19,7 +19,7 @@ use Friendica\Core\Config;
|
|||
require_once 'boot.php';
|
||||
require_once 'object/BaseObject.php';
|
||||
|
||||
$a = new App;
|
||||
$a = new App(__DIR__);
|
||||
BaseObject::set_app($a);
|
||||
|
||||
// We assume that the index.php is called by a frontend process
|
||||
|
|
54
src/App.php
54
src/App.php
|
@ -40,6 +40,7 @@ class App {
|
|||
public $module;
|
||||
public $pager;
|
||||
public $strings;
|
||||
public $basepath;
|
||||
public $path;
|
||||
public $hooks;
|
||||
public $timezone;
|
||||
|
@ -112,8 +113,10 @@ class App {
|
|||
|
||||
/**
|
||||
* @brief App constructor.
|
||||
*
|
||||
* @param string $basepath Path to the app base folder
|
||||
*/
|
||||
function __construct() {
|
||||
function __construct($basepath) {
|
||||
|
||||
global $default_timezone;
|
||||
|
||||
|
@ -154,13 +157,6 @@ class App {
|
|||
|
||||
startup();
|
||||
|
||||
set_include_path(
|
||||
get_include_path() . PATH_SEPARATOR
|
||||
. 'include' . PATH_SEPARATOR
|
||||
. 'library' . PATH_SEPARATOR
|
||||
. 'library/langdet' . PATH_SEPARATOR
|
||||
. '.');
|
||||
|
||||
$this->scheme = 'http';
|
||||
|
||||
if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
|
||||
|
@ -195,6 +191,20 @@ class App {
|
|||
$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') {
|
||||
$this->set_baseurl(array_pop($_SERVER['argv']));
|
||||
$_SERVER['argc'] --;
|
||||
|
@ -284,18 +294,28 @@ class App {
|
|||
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() {
|
||||
$basepath = get_config('system', 'basepath');
|
||||
|
||||
if ($basepath == '') {
|
||||
$basepath = dirname(__FILE__);
|
||||
if (isset($this)) {
|
||||
$basepath = $this->basepath;
|
||||
}
|
||||
|
||||
if ($basepath == '') {
|
||||
if (! $basepath) {
|
||||
$basepath = Config::get('system', 'basepath');
|
||||
}
|
||||
|
||||
if (! $basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
|
||||
$basepath = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
if ($basepath == '') {
|
||||
if (! $basepath && x($_SERVER, 'PWD')) {
|
||||
$basepath = $_SERVER['PWD'];
|
||||
}
|
||||
|
||||
|
@ -900,10 +920,10 @@ class App {
|
|||
return;
|
||||
}
|
||||
|
||||
if (get_config('system', 'proc_windows')) {
|
||||
$resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));
|
||||
if (Config::get('system', 'proc_windows')) {
|
||||
$resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());
|
||||
} else {
|
||||
$resource = proc_open($cmdline . ' &', array(), $foo, dirname(__FILE__));
|
||||
$resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());
|
||||
}
|
||||
if (!is_resource($resource)) {
|
||||
logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);
|
||||
|
|
|
@ -11,7 +11,7 @@ use Friendica\App;
|
|||
*/
|
||||
require_once("boot.php");
|
||||
|
||||
$a = new App;
|
||||
$a = new App(dirname(__DIR__));
|
||||
@include(".htconfig.php");
|
||||
|
||||
$lang = get_browser_language();
|
||||
|
|
|
@ -5,7 +5,7 @@ use Friendica\Core\Config;
|
|||
|
||||
require_once("boot.php");
|
||||
|
||||
$a = new App;
|
||||
$a = new App(dirname(__DIR__));
|
||||
@include(".htconfig.php");
|
||||
|
||||
$lang = get_browser_language();
|
||||
|
|
|
@ -12,7 +12,7 @@ ini_set('log_errors', '0');
|
|||
|
||||
include 'boot.php';
|
||||
|
||||
$a = new App();
|
||||
$a = new App(dirname(__DIR__));
|
||||
|
||||
if (x($a->config, 'php_path')) {
|
||||
$phpath = $a->config['php_path'];
|
||||
|
|
Loading…
Reference in a new issue