refactor: autoprefixing class includes

This commit is contained in:
Martin Ambrus
2017-10-28 02:17:43 +02:00
parent a9bf045a82
commit 6f7c70a0d7
5 changed files with 103 additions and 52 deletions
+13 -16
View File
@@ -1,19 +1,4 @@
<?php
$src_prefix = '';
if (substr(getcwd(), -5) === 'Admin') {
$src_prefix = '../';
}
if (substr(getcwd(), -4) === 'Mods') {
$src_prefix = '../../';
}
if (substr(getcwd(), -7) === 'include') {
$src_prefix = '../../';
}
include_once($src_prefix."src/Entity/User.php");
use App\Entity\User;
#################################################################################
@@ -32,7 +17,19 @@ use App\Entity\User;
## ##
#################################################################################
include("Session.php");
global $autoprefix;
// go max 5 levels up - we don't have folders that go deeper than that
$autoprefix = '';
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i);
if (file_exists($autoprefix.'autoloader.php')) {
// we have our path, let's leave
break;
}
}
include($autoprefix."GameEngine/Session.php");
class Account {
+14 -5
View File
@@ -8,13 +8,22 @@
## Copyright: TravianZ (c) 2014. All rights reserved. ##
#########################################################
include_once("../../../src/Entity/User.php");
use App\Entity\User;
include_once("../../config.php");
include_once("../../Session.php");
include_once("../../Automation.php");
include_once("../../Database.php");
// go max 5 levels up - we don't have folders that go deeper than that
$autoprefix = '';
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i);
if (file_exists($autoprefix.'autoloader.php')) {
// we have our path, let's leave
break;
}
}
include_once($autoprefix."GameEngine/config.php");
include_once($autoprefix."GameEngine/Session.php");
include_once($autoprefix."GameEngine/Automation.php");
include_once($autoprefix."GameEngine/Database.php");
$GLOBALS["link"] = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
mysqli_select_db($GLOBALS["link"], SQL_DB);
+20 -1
View File
@@ -16,9 +16,28 @@
## ##
#################################################################################
include_once("src/Entity/User.php");
use App\Entity\User;
global $autoprefix;
// even with autoloader created, we can't use it here yet, as it's not been created
// ... so, let's see where it is and include it
$autoloader_found = false;
// go max 5 levels up - we don't have folders that go deeper than that
$autoprefix = '';
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i);
if (file_exists($autoprefix.'autoloader.php')) {
$autoloader_found = true;
include_once $autoprefix.'autoloader.php';
break;
}
}
if (!$autoloader_found) {
die('Could not find autoloading class.');
}
class Alliance {
public $gotInvite = false;
+13 -1
View File
@@ -20,7 +20,19 @@ mb_internal_encoding("UTF-8"); // Add for utf8 varriables.
## ##
#################################################################################
if(!file_exists('GameEngine/config.php') && !file_exists('../GameEngine/config.php') && !file_exists('../../GameEngine/config.php') && !file_exists('../../config.php')) {
global $autoprefix;
// go max 5 levels up - we don't have folders that go deeper than that
$autoprefix = '';
for ($i = 0; $i < 5; $i++) {
$autoprefix = str_repeat('../', $i);
if (file_exists($autoprefix.'autoloader.php')) {
// we have our path, let's leave
break;
}
}
if(!file_exists($autoprefix.'GameEngine/config.php')) {
header("Location: install/");
exit;
}