Depend on find-autoloader instead of "../../../" madness

This commit is contained in:
Greyscale 2020-11-22 08:38:44 +01:00
parent 0862121586
commit ac3bc88772
No known key found for this signature in database
GPG key ID: C6178C19949CFFE3
3 changed files with 23 additions and 6 deletions

21
bin/find-autoloader.php Normal file
View file

@ -0,0 +1,21 @@
<?php
function detectAndLoadVendor($path = __DIR__): void
{
$path = realpath($path);
if ('/' == $path) {
die("Could not find a suitable /vendor directory! Maybe you need to run composer install!\n");
}
foreach (new DirectoryIterator($path) as $fileInfo) {
if ($fileInfo->isDir() && 'vendor' == $fileInfo->getFilename()) {
define('VENDOR_PATH', $fileInfo->getRealPath());
require_once VENDOR_PATH.'/autoload.php';
return;
}
}
detectAndLoadVendor($path.'/../');
}
detectAndLoadVendor();

View file

@ -1,6 +1,6 @@
#!/usr/bin/php
<?php
require_once(__DIR__ . "/../../../../vendor/autoload.php");
require_once(__DIR__ . "/find-autoloader.php");
use Benzine\App;
use Benzine\Services\QueueService;

View file

@ -1,10 +1,6 @@
#!/usr/bin/php
<?php
$projRoot = __DIR__ . "/../../../..";
if(file_exists("{$projRoot}/bootstrap.php")){
require_once("{$projRoot}/bootstrap.php");
}
require_once("{$projRoot}/vendor/autoload.php");
require_once(__DIR__ . "/find-autoloader.php");
use Benzine\Workers\AbstractQueueWorker;
use duncan3dc\Forker\Fork;