|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -$vendorPath = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'vendor'; |
4 |
| -$composerAutoload = $vendorPath . DIRECTORY_SEPARATOR . 'autoload.php'; |
| 3 | +function root_dir( $dir, $levels ) { |
| 4 | + if ( $levels == 0 ) { |
| 5 | + return $dir; |
| 6 | + } else { |
| 7 | + return root_dir( dirname($dir), --$levels ); |
| 8 | + } |
| 9 | +} |
5 | 10 |
|
6 | 11 | $reason = '';
|
7 | 12 | $loadable = TRUE;
|
8 |
| -if ( ! file_exists($vendorPath) ) { |
9 |
| - $loadable = FALSE; |
10 |
| - $reason = "The 'vendor' folder is missing. (expected at '" . $vendorPath . "')"; |
11 |
| -} |
| 13 | + |
| 14 | +// First, we will assume that this is a standard composer distribution and |
| 15 | +// look for the autoload.php in that context... |
| 16 | +$topDir = root_dir( __FILE__, 2 ); |
| 17 | +print "1) Path[top] '" . $topDir . "'" . PHP_EOL; |
| 18 | +$composerAutoload = $topDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; |
12 | 19 | if ( ! file_exists($composerAutoload) ) {
|
13 |
| - $loadable = FALSE; |
14 |
| - $reason = "The 'autoload.php' file is missing. (expected at '" . $composerAutoload . "')"; |
| 20 | + print " '" . $composerAutoload . "' NOT FOUND". PHP_EOL; |
| 21 | + $topDir = root_dir( __FILE__, 1 ); |
| 22 | + print "2) Path[top] '" . $topDir . "'" . PHP_EOL; |
| 23 | + $composerAutoload = $topDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; |
| 24 | + if ( ! file_exists($composerAutoload) ) { |
| 25 | + $loadable = FALSE; |
| 26 | + $reason = "The 'autoload.php' file was not found. (expected at '" . $composerAutoload . "')"; |
| 27 | + } |
15 | 28 | }
|
16 | 29 |
|
17 | 30 | if ( $loadable ) {
|
| 31 | + "Loading: '" . $composerAutoload . "'" . PHP_EOL; |
18 | 32 | require $composerAutoload;
|
19 | 33 | } else {
|
20 | 34 | print "Could not bootstrap the example program:" . PHP_EOL;
|
|
0 commit comments