-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolve.composer.php
67 lines (57 loc) · 2.16 KB
/
resolve.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Resolve Composer dependencies
*
* @package agenda
* @subpackage build
*
* @var array $options
* @var xPDOObject $object
*/
use Composer\Console\HtmlOutputFormatter;
use Composer\Factory;
use Composer\Installer;
use Composer\IO\BufferIO;
use Symfony\Component\Console\Output\StreamOutput;
$success = true;
if ($object->xpdo) {
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
/** @var modX $modx */
$modx = &$object->xpdo;
$modx->log(xPDO::LOG_LEVEL_INFO, 'Installing/updating dependencies, this may take some time...');
$path = MODX_CORE_PATH . "components/{$options['namespace']}/";
// Set Composer environment variables
putenv("COMPOSER={$path}composer.json");
putenv("COMPOSER_HOME={$path}.composer");
putenv("COMPOSER_VENDOR_DIR={$path}vendor/");
// Change the path to the package namespace folder, to prevent autoloading other namespaces
chdir($path);
require "phar://{$path}composer.phar/vendor/autoload.php";
// Run Composer without proc_open/exec
$io = new BufferIO('', StreamOutput::VERBOSITY_NORMAL, new HtmlOutputFormatter());
$composer = Factory::create($io);
$install = Installer::create($io, $composer);
$install
->setPreferDist(true)
->setDevMode(false)
->setOptimizeAutoloader(true)
->setUpdate(false)
->setPreferStable(true);
try {
$install->run();
} catch (Exception $e) {
$modx->log(xPDO::LOG_LEVEL_ERROR, get_class($e) . ' installing dependencies: ' . $e->getMessage());
echo get_class($e) . ': ' . $e->getMessage() . "\n";
$success = false;
}
$output = $io->getOutput();
$output = nl2br(trim($output));
$modx->log(xPDO::LOG_LEVEL_INFO, $output);
break;
case xPDOTransport::ACTION_UNINSTALL:
break;
}
}
return $success;