|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | // Set include path to look for classes in the models directory, then in the controllers directory |
4 | | -set_include_path(get_include_path() . PATH_SEPARATOR . 'models' . PATH_SEPARATOR . 'controllers'); |
| 4 | +$projectDir = dirname(dirname(__FILE__)); |
| 5 | +$classDirectories = ['models', 'controllers']; |
| 6 | +$classPaths = []; |
| 7 | +foreach ($classDirectories as $dir) { |
| 8 | + $classPaths[] = $projectDir . DIRECTORY_SEPARATOR . $dir; |
| 9 | +} |
| 10 | +$classPaths[] = get_include_path(); |
| 11 | +$includePath = implode(PATH_SEPARATOR, $classPaths); |
| 12 | +set_include_path($includePath); |
5 | 13 |
|
6 | | -// Register the autoload function to automatically include classes |
| 14 | +// Set up autoload function |
7 | 15 | spl_autoload_register(['Controller', 'autoload']); |
8 | 16 |
|
9 | 17 | /** |
@@ -196,21 +204,26 @@ protected function checkDependencies() |
196 | 204 | $missing[] = 'PDO'; |
197 | 205 | } |
198 | 206 |
|
199 | | - // Version 3.6.19 is required for foreign key support and cascade support |
200 | | - if (! extension_loaded('sqlite3')) { |
201 | | - $missing[] = 'sqlite3 version 3.6.19 or higher'; |
| 207 | + if (! extension_loaded('pdo_sqlite')) { |
| 208 | + $missing[] = 'pdo_sqlite'; |
202 | 209 | } else { |
203 | | - $versionArray = sqlite3::version(); |
204 | | - $versionString = $versionArray['versionString']; |
| 210 | + // Version 3.6.19 is required for foreign key support and cascade support |
| 211 | + // Check version here |
| 212 | + if (extension_loaded('sqlite3')) { |
| 213 | + $versionArray = sqlite3::version(); |
| 214 | + $versionString = $versionArray['versionString']; |
| 215 | + } else { |
| 216 | + // If we don't have the sqlite extension, but we have the pdo_sqlite extension, |
| 217 | + // Use an alternate method to check the sqlite version. |
| 218 | + $pdo = new PDO('sqlite::memory:'); |
| 219 | + $versionString = $pdo->query('select sqlite_version()')->fetch()[0]; |
| 220 | + } |
| 221 | + |
205 | 222 | if (version_compare($versionString, '3.6.19', '<')) { |
206 | 223 | $missing[] = 'sqlite3 version 3.6.19 or higher'; |
207 | 224 | } |
208 | 225 | } |
209 | 226 |
|
210 | | - if (! extension_loaded('pdo_sqlite')) { |
211 | | - $missing[] = 'pdo_sqlite'; |
212 | | - } |
213 | | - |
214 | 227 | if (! empty($missing)) { |
215 | 228 | throw new RuntimeException("The following PHP extensions are required:\n\n" . implode("\n", $missing)); |
216 | 229 | } |
|
0 commit comments