Skip to content

Commit bfbfbcc

Browse files
committed
Bug fix for Windows/IIS - use a more reliable way of setting the include path
1 parent b1bbe28 commit bfbfbcc

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

controllers/Controller.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<?php
22

33
// 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);
513

6-
// Register the autoload function to automatically include classes
14+
// Set up autoload function
715
spl_autoload_register(['Controller', 'autoload']);
816

917
/**
@@ -196,21 +204,26 @@ protected function checkDependencies()
196204
$missing[] = 'PDO';
197205
}
198206

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';
202209
} 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+
205222
if (version_compare($versionString, '3.6.19', '<')) {
206223
$missing[] = 'sqlite3 version 3.6.19 or higher';
207224
}
208225
}
209226

210-
if (! extension_loaded('pdo_sqlite')) {
211-
$missing[] = 'pdo_sqlite';
212-
}
213-
214227
if (! empty($missing)) {
215228
throw new RuntimeException("The following PHP extensions are required:\n\n" . implode("\n", $missing));
216229
}

0 commit comments

Comments
 (0)