-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfg-composer.php
50 lines (44 loc) · 1.48 KB
/
fg-composer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
function locateComposerFile()
{
$filename = getenv('COMPOSER') ?: 'composer.json';
$path = __FILE__;
$composerFile = '';
do {
$path = dirname($path);
if ($composerFile = realpath($path.'/'.$filename)) {
break;
}
} while($path !== '/');
return $composerFile;
}
function locateComposerVendors()
{
$composerFile = locateComposerFile();
$config = (array) loadComposerConfig($composerFile);
if (empty($config['vendor-dir'])) {
$composerHome = getenv('COMPOSER_HOME') ?: getenv('HOME').'/.composer';
$configFile = '';
if ($composerHome = realpath($composerHome)) {
$configFile = realpath($composerHome.'/config.json');
}
if ($configFile) {
$config = (array) loadComposerConfig($configFile);
}
}
$vendorDir = empty($config['vendor-dir']) ? 'vendor' : $config['vendor-dir'];
return realpath($vendorDir) ?: realpath(dirname($composerFile).'/'.$vendorDir);
}
function loadComposerConfig($file)
{
if (!is_readable($file)) {
return null;
}
$contents = json_decode(file_get_contents($file), true);
return empty($contents['config']) ? null : $contents['config'];
}
global $composerLoader;
$composerLoader = require locateComposerVendors().'/autoload.php';
if (class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry')) {
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($composerLoader, 'loadClass'));
}