Skip to content

Commit d39004d

Browse files
committed
Refactoring
changed Docroot to Routes for clarity
1 parent 3b80284 commit d39004d

File tree

15 files changed

+112
-105
lines changed

15 files changed

+112
-105
lines changed

App.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use TempusProjectCore\Classes\Debug as Debug;
2222
use TempusProjectCore\Classes\Config as Config;
23-
use TempusProjectCore\Functions\Docroot as Docroot;
23+
use TempusProjectCore\Functions\Routes as Routes;
2424
use TempusProjectCore\Classes\Input as Input;
2525

2626
class App
@@ -53,15 +53,15 @@ public function __construct($urlDirected = null)
5353
Debug::log("Class Initiated: " . __CLASS__);
5454

5555
// Set Default Controller Locations
56-
$this->controllerPath = Docroot::getFull() . 'Controllers/';
57-
$this->indexPath = Docroot::getFull();
56+
$this->controllerPath = Routes::getLocation('controllers')->folder;
57+
$this->indexPath = Routes::getFull();
5858

5959
// Set the application url to be used
6060
if (!empty($urlDirected)) {
6161
$this->directed = true;
62-
$this->url = Docroot::parseUrl($urlDirected);
62+
$this->url = Routes::parseUrl($urlDirected);
6363
} else {
64-
$this->url = Docroot::parseUrl();
64+
$this->url = Routes::parseUrl();
6565
}
6666

6767
// Find the Controller
@@ -71,7 +71,7 @@ public function __construct($urlDirected = null)
7171

7272
// Ensure the controller is required
7373
Debug::log("Requiring Controller: $this->controllerName");
74-
require $this->path . $this->controllerName . '.php'; // docroot
74+
require $this->path . $this->controllerName . '.php';
7575

7676
// Find the Method
7777
$this->methodName = $this->getMethod();
@@ -128,30 +128,30 @@ private function getController()
128128
{
129129
if (empty($this->url[0])) {
130130
Debug::info('No Controller Specified.');
131-
$this->path = $this->controllerPath; // docroot
131+
$this->path = $this->controllerPath;
132132
return $this->controllerName;
133133
}
134134
if ($this->directed) {
135135
if (file_exists($this->indexPath . $this->url[0] . '.php')) {
136136
Debug::log("Modifying the controller from $this->controllerName to " . $this->url[0]);
137137
$out = array_shift($this->url);
138-
$this->path = $this->indexPath; // docroot
138+
$this->path = $this->indexPath;
139139
return strtolower($out);
140140
} elseif (file_exists($this->controllerPath . $this->url[0] . '.php')) {
141141
Debug::log("Modifying the controller from $this->controllerName to " . $this->url[0]);
142142
$out = array_shift($this->url);
143-
$this->path = $this->controllerPath; // docroot
143+
$this->path = $this->controllerPath;
144144
return strtolower($out);
145145
}
146146
}
147147
if (!$this->directed && file_exists($this->controllerPath . $this->url[0] . '.php')) {
148148
Debug::log("Modifying the controller from $this->controllerName to " . $this->url[0]);
149149
$out = array_shift($this->url);
150-
$this->path = $this->controllerPath; // docroot
150+
$this->path = $this->controllerPath;
151151
return strtolower($out);
152152
}
153153
Debug::info('Could not locate specified controller: ' . $this->url[0]);
154-
$this->path = $this->controllerPath; // docroot
154+
$this->path = $this->controllerPath;
155155
array_shift($this->url);
156156
return $this->controllerName;
157157
}

Classes/Check.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace TempusProjectCore\Classes;
1717

18-
use TempusProjectCore\Functions\Docroot as Docroot;
18+
use TempusProjectCore\Functions\Routes as Routes;
1919

2020
class Check
2121
{
@@ -26,7 +26,7 @@ class Check
2626
private static $errorLogUser = [];
2727

2828
/**
29-
* Creates a new DB connection, but only if we need it.
29+
* Creates a new DB instance, but only if we need it.
3030
*/
3131
public static function connect()
3232
{
@@ -121,7 +121,7 @@ public static function userErrors()
121121
public static function form($name)
122122
{
123123
if (empty(self::$formValidator)) {
124-
$docLocation = Docroot::getLocation('formChecks');
124+
$docLocation = Routes::getLocation('formChecks');
125125
if ($docLocation->error) {
126126
self::addError($docLocation->errorString);
127127

Classes/Config.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace TempusProjectCore\Classes;
1717

18-
use TempusProjectCore\Functions\Docroot as Docroot;
18+
use TempusProjectCore\Functions\Routes as Routes;
1919

2020
class Config
2121
{
@@ -52,11 +52,11 @@ private static function load()
5252
*/
5353
public static function getConfig()
5454
{
55-
$docLocation = Docroot::getLocation('appConfig');
55+
$docLocation = Routes::getLocation('appConfig');
5656
if ($docLocation->error) {
57-
$docLocation = Docroot::getLocation('appConfigDefault');
57+
$docLocation = Routes::getLocation('appConfigDefault');
5858
if ($docLocation->error) {
59-
$docLocation = Docroot::getLocation('configDefault');
59+
$docLocation = Routes::getLocation('configDefault');
6060
}
6161
}
6262
return json_decode(file_get_contents($docLocation->fullPath), true);
@@ -135,11 +135,11 @@ public static function saveConfig($default = false)
135135
self::load();
136136
}
137137
if ($default) {
138-
if (!file_put_contents(Docroot::getLocation('appConfigDefault')->fullPath, json_encode(self::$config))) {
138+
if (!file_put_contents(Routes::getLocation('appConfigDefault')->fullPath, json_encode(self::$config))) {
139139
return false;
140140
}
141141
}
142-
if (file_put_contents(Docroot::getLocation('appConfig')->fullPath, json_encode(self::$config))) {
142+
if (file_put_contents(Routes::getLocation('appConfig')->fullPath, json_encode(self::$config))) {
143143
return true;
144144
}
145145
return false;
@@ -254,7 +254,7 @@ public static function addConfig($parent, $name, $value)
254254
*/
255255
public static function generateConfig($mods = [])
256256
{
257-
$docLocation = Docroot::getLocation('appConfig');
257+
$docLocation = Routes::getLocation('appConfig');
258258
if (!$docLocation->error) {
259259
if (!self::$override) {
260260
Debug::error('config file already exists');
@@ -263,9 +263,9 @@ public static function generateConfig($mods = [])
263263
}
264264
}
265265

266-
$docLocation = Docroot::getLocation('appConfigDefault');
266+
$docLocation = Routes::getLocation('appConfigDefault');
267267
if ($docLocation->error) {
268-
$docLocation = Docroot::getLocation('configDefault');
268+
$docLocation = Routes::getLocation('configDefault');
269269
}
270270

271271
self::$config = json_decode(file_get_contents($docLocation->fullPath), true);

Classes/Debug.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
namespace TempusProjectCore\Classes;
2020

21-
use TempusProjectCore\Functions\Docroot;
21+
use TempusProjectCore\Functions\Routes;
2222
use TempusProjectCore\Core\Installer;
2323

24-
require_once Docroot::getFull() . 'vendor/TheTempusProject/TempusDebugger/TempusDebugger.php';
24+
require_once Routes::getFull() . 'vendor/TheTempusProject/TempusDebugger/TempusDebugger.php';
2525

2626
use TempusDebugger\TempusDebugger;
2727

Classes/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace TempusProjectCore\Classes;
1717

1818
use TempusProjectCore\Core\Template as Template;
19-
use TempusProjectCore\Functions\Docroot as Docroot;
19+
use TempusProjectCore\Functions\Routes as Routes;
2020

2121
class Email
2222
{
@@ -201,7 +201,7 @@ public static function build()
201201
self::$header = 'From: ' . Config::get('main/name') . ' <noreply@' . $_SERVER['HTTP_HOST'] . ">\r\n";
202202
self::$header .= "MIME-Version: 1.0\r\n";
203203
self::$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
204-
$url = parse_url(Docroot::getAddress(), PHP_URL_HOST);
204+
$url = parse_url(Routes::getAddress(), PHP_URL_HOST);
205205
$parts = explode(".", $url);
206206
$count = count($parts);
207207
if ($count > 2) {

Classes/Image.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace TempusProjectCore\Classes;
2020

21-
use TempusProjectCore\Functions\Docroot as Docroot;
21+
use TempusProjectCore\Functions\Routes as Routes;
2222

2323
class Image
2424
{
@@ -33,18 +33,16 @@ class Image
3333
* @param string $folder - The sub-folder to store the uploaded image.
3434
*
3535
* @return boolean
36-
*
37-
* @todo this folder stuff could be handled by the docroot function
3836
*/
3937
public static function upload($fieldname, $folder)
4038
{
41-
$uploaddir = Docroot::getLocation('imageUploadFolder', $folder)->fullPath;
39+
$uploaddir = Routes::getLocation('imageUploadFolder', $folder)->fullPath;
4240
if (!Check::imageUpload($fieldname)) {
4341
Debug::error(Check::systemErrors());
4442
return false;
4543
}
4644
// @todo Let's try and avoid 777 if possible
47-
// Try catch here for better error handling
45+
// Try catch here for better error handling
4846
if (!file_exists($uploaddir)) {
4947
Debug::Info('Creating Directory because it does not exist');
5048
mkdir($uploaddir, 0777, true);

Classes/Permission.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace TempusProjectCore\Classes;
1717

18-
use TempusProjectCore\Functions\Docroot as Docroot;
18+
use TempusProjectCore\Functions\Routes as Routes;
1919

2020
class Permission
2121
{
@@ -30,11 +30,11 @@ private static function load()
3030

3131
public static function getPerms()
3232
{
33-
$docLocation = Docroot::getLocation('appPermissions');
33+
$docLocation = Routes::getLocation('appPermissions');
3434
if ($docLocation->error) {
35-
$docLocation = Docroot::getLocation('appPermissionsDefault');
35+
$docLocation = Routes::getLocation('appPermissionsDefault');
3636
if ($docLocation->error) {
37-
$docLocation = Docroot::getLocation('permissionsDefault');
37+
$docLocation = Routes::getLocation('permissionsDefault');
3838
}
3939
}
4040
return json_decode(file_get_contents($docLocation->fullPath), true);
@@ -59,12 +59,12 @@ public static function savePerms($default = false)
5959
self::load();
6060
}
6161
if ($default) {
62-
if (file_put_contents(Docroot::getLocation('appPermissionsDefault')->fullPath, json_encode(self::$permissions))) {
62+
if (file_put_contents(Routes::getLocation('appPermissionsDefault')->fullPath, json_encode(self::$permissions))) {
6363
return true;
6464
}
6565
return false;
6666
}
67-
if (file_put_contents(Docroot::getLocation('appPermissions')->fullPath, json_encode(self::$permissions))) {
67+
if (file_put_contents(Routes::getLocation('appPermissions')->fullPath, json_encode(self::$permissions))) {
6868
return true;
6969
}
7070
return false;

Classes/Preference.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace TempusProjectCore\Classes;
1717

18-
use TempusProjectCore\Functions\Docroot;
18+
use TempusProjectCore\Functions\Routes;
1919
use TempusProjectCore\Classes\Debug;
2020

2121
class Preference
@@ -31,11 +31,11 @@ private static function load()
3131

3232
public static function getPrefs()
3333
{
34-
$docLocation = Docroot::getLocation('appPreferences');
34+
$docLocation = Routes::getLocation('appPreferences');
3535
if ($docLocation->error) {
36-
$docLocation = Docroot::getLocation('appPreferencesDefault');
36+
$docLocation = Routes::getLocation('appPreferencesDefault');
3737
if ($docLocation->error) {
38-
$docLocation = Docroot::getLocation('preferencesDefault');
38+
$docLocation = Routes::getLocation('preferencesDefault');
3939
}
4040
}
4141
return json_decode(file_get_contents($docLocation->fullPath), true);
@@ -60,12 +60,12 @@ public static function savePrefs($default = false)
6060
self::load();
6161
}
6262
if ($default) {
63-
if (file_put_contents(Docroot::getLocation('appPreferencesDefault')->fullPath, json_encode(self::$preferences))) {
63+
if (file_put_contents(Routes::getLocation('appPreferencesDefault')->fullPath, json_encode(self::$preferences))) {
6464
return true;
6565
}
6666
return false;
6767
}
68-
if (file_put_contents(Docroot::getLocation('appPreferences')->fullPath, json_encode(self::$preferences))) {
68+
if (file_put_contents(Routes::getLocation('appPreferences')->fullPath, json_encode(self::$preferences))) {
6969
return true;
7070
}
7171
return false;

Classes/Redirect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace TempusProjectCore\Classes;
1717

18-
use TempusProjectCore\Functions\Docroot as Docroot;
18+
use TempusProjectCore\Functions\Routes as Routes;
1919

2020
class Redirect
2121
{
@@ -34,12 +34,12 @@ public static function to($data)
3434
exit();
3535
}
3636
if (is_numeric($data)) {
37-
header('Location: ' . Docroot::getAddress() . 'Errors/' . $data);
37+
header('Location: ' . Routes::getAddress() . 'Errors/' . $data);
3838
} else {
3939
if (!Check::path($data)) {
4040
Debug::info('Invalid Redirect path.');
4141
} else {
42-
header('Location: ' . Docroot::getAddress() . $data);
42+
header('Location: ' . Routes::getAddress() . $data);
4343
}
4444
}
4545
}

Core/Controller.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use TempusProjectCore\Classes\CustomException;
2222
use TempusProjectCore\Classes\Pagination;
23-
use TempusProjectCore\Functions\Docroot;
23+
use TempusProjectCore\Functions\Routes;
2424
use TempusProjectCore\Classes\Session;
2525
use TempusProjectCore\Classes\Cookie;
2626
use TempusProjectCore\Classes\Config;
@@ -77,15 +77,15 @@ public function __construct()
7777
{
7878
Debug::group("Controller Constructor", 1);
7979
Issue::checkSessions();
80-
Debug::warn('Requested URL: ' . Docroot::getUrl());
81-
self::$base = Docroot::getAddress();
82-
self::$location = Docroot::getFull();
80+
Debug::warn('Requested URL: ' . Routes::getUrl());
81+
self::$base = Routes::getAddress();
82+
self::$location = Routes::getFull();
8383
self::$cookiePrefix = Config::get('cookie/cookiePrefix');
8484
self::$sessionPrefix = Config::get('session/sessionPrefix');
8585
self::$db = DB::getInstance();
8686
self::$template = new Template();
87-
self::$activeGroup = json_decode(file_get_contents(Docroot::getLocation('permissionsDefault')->fullPath), true);
88-
self::$activePrefs = json_decode(file_get_contents(Docroot::getLocation('preferencesDefault')->fullPath));
87+
self::$activeGroup = json_decode(file_get_contents(Routes::getLocation('permissionsDefault')->fullPath), true);
88+
self::$activePrefs = json_decode(file_get_contents(Routes::getLocation('preferencesDefault')->fullPath));
8989
Debug::gend();
9090
}
9191

@@ -120,7 +120,7 @@ protected function build()
120120
protected function model($modelName)
121121
{
122122
Debug::group("Model: $modelName", 1);
123-
$docLocation = Docroot::getLocation('models', $modelName);
123+
$docLocation = Routes::getLocation('models', $modelName);
124124
if ($docLocation->error) {
125125
new CustomException('model', $docLocation->errorString);
126126
} else {

0 commit comments

Comments
 (0)