Skip to content

Commit fa77f35

Browse files
committed
fix symfony-autocomplete composer vendor
bin/symfony-autocomplete did not honor COMPOSER_VENDOR_DIR and treated it as if it is the default value "vendor" only. however it is part of the composer install protocol and required for the bin-stubs autoloading. it should not be hard-encoded to the default value only. fix is to use COMPOSER_VENDOR_DIR as absolute path, as relative path to PWD and as relative path to bin/symfony-autocomplete given the first attempt to try requiring from __DIR__.'/../../../autoload.php' failed. NOTE: use of include_once instead of require_once is intended here, the EA inspection is misleading on it as _once was and still is intended. this is similar for "acme" in tests, but with the difference that during build time we insist to know that COMPOSER_VENDOR_DIR is always relative to the project root, YMMV. report: #76
1 parent f7c0779 commit fa77f35

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

bin/symfony-autocomplete

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ if (function_exists('ini_set')) {
66
ini_set('display_errors', 'stderr');
77
}
88

9-
if (file_exists($autoload = __DIR__.'/../../../autoload.php')) {
10-
require_once $autoload;
11-
} else {
12-
require_once __DIR__.'/../vendor/autoload.php';
13-
}
9+
(/* require vendor autoload file (Composer) */ static function () {
10+
$includeIfExists = static function ($file) {
11+
/** @noinspection UsingInclusionOnceReturnValueInspection intended */
12+
return file_exists($file) ? include_once($file) : false;
13+
};
14+
if ((!$includeIfExists(
15+
__DIR__ . '/../../../autoload.php'
16+
) &&
17+
empty($_SERVER['COMPOSER_VENDOR_DIR'])) ||
18+
(!$includeIfExists(
19+
$_SERVER['COMPOSER_VENDOR_DIR'] . '/autoload.php'
20+
) &&
21+
!$includeIfExists(
22+
__DIR__ . '/../' . $_SERVER['COMPOSER_VENDOR_DIR'] .
23+
'/autoload.php'
24+
)
25+
)
26+
) {
27+
require_once __DIR__ . '/../vendor/autoload.php';
28+
}
29+
})();
1430

1531
use Bamarni\Symfony\Console\Autocomplete\Application;
1632

tests/fixtures/acme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4-
require __DIR__.'/../../vendor/autoload.php';
4+
require __DIR__.'/../../' . ($_SERVER['COMPOSER_VENDOR_DIR'] ?? 'vendor') . '/autoload.php';
55

66
use Symfony\Component\Console\Application;
77
use Symfony\Component\Console\Command\Command;

0 commit comments

Comments
 (0)