This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
/
append_composer.php
43 lines (42 loc) · 1.6 KB
/
append_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
<?php
/**
* Script for appending accepted plugins to a composer.json file
*
* Normally composer will prompt us to accept plugins it doesn't trust but this is
* no good if we are doing something automatically like installing simplesamlphp where
* the composer.json file comes supplied so we can pass in information to this file to
* manipulate the allowed plugins object so we can install things automatically
*
* $argv contains
* [0] name of this script
* [1] path to the composer.json file, eg htdocs/auth/saml/extlib/simplesamlphp/composer.json
* [2]+ the name of the plugins to accept, eg simplesamlphp/composer-module-installer
*
* So for example to allow the simplesamlphp/composer-module-installer plugin without being prompted
* php append_composer.php htdocs/auth/saml/extlib/simplesamlphp/composer.json simplesamlphp/composer-module-installer
*/
$pluginstoallow = array();
$composerfile = null;
if (count($argv) > 1) {
$composerfile = $argv[1];
for ($i = 2; $i < count($argv); $i++) {
$pluginstoallow[] = $argv[$i];
}
}
if ($composerfile && $file = file_get_contents($composerfile)) {
$file = json_decode($file);
if (!isset($file->config)) {
$file->config = new stdClass();
}
if (!isset($file->config->{'allow-plugins'})) {
$file->config->{'allow-plugins'} = new stdClass();
}
foreach ($pluginstoallow as $plugin) {
$file->config->{'allow-plugins'}->{$plugin} = true;
}
$file = json_encode($file, JSON_PRETTY_PRINT);
file_put_contents($composerfile, $file);
}
else {
throw new Exception('Unable to find composer.json file');
}