Skip to content

Commit

Permalink
Update autoload path resolution (#189)
Browse files Browse the repository at this point in the history
This change uses various possible path locations to locate the `autoload.php` file and throws an error if not found.
It closes #188
  • Loading branch information
SmetDenis authored May 8, 2024
1 parent e79986b commit 8a9fb9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ jobs:
run: |
! $BLUEPRINT $CMD_VALIDATE $INVALID_TEST
- name: Test as composer package
run: |
mkdir -pv ./build/composer-test
cd ./build/composer-test
composer init --no-interaction --name="test/test"
composer require jbzoo/csv-blueprint
./vendor/bin/csv-blueprint || true
./vendor/bin/csv-blueprint $CMD_VALIDATE $VALID_TEST || true
./vendor/bin/csv-blueprint $CMD_VALIDATE $INVALID_TEST || true
verify-phar-binary:
name: Verify Phar
Expand Down
20 changes: 19 additions & 1 deletion csv-blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@
namespace JBZoo\CsvBlueprint;

\define('PATH_ROOT', __DIR__);
require_once PATH_ROOT . '/vendor/autoload.php';

foreach (
[
PATH_ROOT . '/../../autoload.php',
PATH_ROOT . '/../vendor/autoload.php',
PATH_ROOT . '/vendor/autoload.php',
] as $file
) {
if (\file_exists($file)) {
\define('JBZOO_AUTOLOAD_FILE', $file);
break;
}
}

if (\defined('JBZOO_AUTOLOAD_FILE')) {
require_once JBZOO_AUTOLOAD_FILE;
} else {
throw new Exception('Cannot find composer autoload file');
}

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
Expand Down

0 comments on commit 8a9fb9e

Please sign in to comment.