Skip to content

Commit b9475d5

Browse files
committed
Merge pull request #36 from vonalbert/patch-1
Refactor of paths detection
2 parents 9f1d541 + 19510a5 commit b9475d5

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

index.php

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,22 @@
101101
* ---------------------------------------------------------------
102102
*/
103103

104-
// Set the current directory correctly for CLI requests
105-
if (defined('STDIN'))
106-
{
107-
chdir(__DIR__);
108-
}
104+
// Ensure the current directory is pointing to the front controller's directory
105+
chdir(__DIR__);
109106

110-
if (($_temp = realpath($system_path)) !== false)
111-
{
112-
$system_path = $_temp.'/';
113-
}
114-
else
107+
// Are the system and application paths correct?
108+
if ( ! realpath($system_path) OR ! is_dir($system_path))
115109
{
116-
// Ensure there's a trailing slash
117-
$system_path = rtrim($system_path, '/').'/';
110+
header('HTTP/1.1 503 Service Unavailable.', true, 503);
111+
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.
112+
pathinfo(__FILE__, PATHINFO_BASENAME);
113+
exit(3); // EXIT_CONFIG
118114
}
119115

120-
// Is the system path correct?
121-
if ( ! is_dir($system_path))
116+
if ( ! realpath($application_folder) OR ! is_dir($application_folder))
122117
{
123118
header('HTTP/1.1 503 Service Unavailable.', true, 503);
124-
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.
119+
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.
125120
pathinfo(__FILE__, PATHINFO_BASENAME);
126121
exit(3); // EXIT_CONFIG
127122
}
@@ -137,36 +132,16 @@
137132
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
138133

139134
// Path to the system folder
140-
define('BASEPATH', realpath(str_replace('\\', '/', $system_path)).DIRECTORY_SEPARATOR);
135+
define('BASEPATH', realpath($system_path).DIRECTORY_SEPARATOR);
141136

142137
// Path to the front controller (this file)
143-
define('FCPATH', realpath(__DIR__).DIRECTORY_SEPARATOR);
138+
define('FCPATH', __DIR__.DIRECTORY_SEPARATOR);
144139

145140
// Path to the writable directory.
146-
define('WRITEPATH', realpath(str_replace('\\', '/', $writable_directory)).DIRECTORY_SEPARATOR);
141+
define('WRITEPATH', realpath($writable_directory).DIRECTORY_SEPARATOR);
147142

148143
// The path to the "application" folder
149-
if (is_dir($application_folder))
150-
{
151-
if (($_temp = realpath($application_folder)) !== false)
152-
{
153-
$application_folder = $_temp;
154-
}
155-
156-
define('APPPATH', realpath($application_folder).DIRECTORY_SEPARATOR);
157-
}
158-
else
159-
{
160-
if ( ! is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
161-
{
162-
header('HTTP/1.1 503 Service Unavailable.', true, 503);
163-
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.
164-
SELF;
165-
exit(3); // EXIT_CONFIG
166-
}
167-
168-
define('APPPATH', realpath(BASEPATH.$application_folder).DIRECTORY_SEPARATOR);
169-
}
144+
define('APPPATH', realpath($application_folder).DIRECTORY_SEPARATOR);
170145

171146
/*
172147
* --------------------------------------------------------------------

0 commit comments

Comments
 (0)