1 | <?php |
---|
2 | |
---|
3 | function formulaires_jouer_composer_charger_dist() { |
---|
4 | if (!autoriser('executer', 'composer')) { |
---|
5 | return null; |
---|
6 | } |
---|
7 | |
---|
8 | $valeurs = array(); |
---|
9 | $valeurs['_composer_json'] = file_get_contents(_FILE_COMPOSER_JSON); |
---|
10 | $valeurs['_composer_phar'] = file_exists(_DIR_COMPOSER . 'composer.phar'); |
---|
11 | $valeurs['message_output'] = ""; |
---|
12 | |
---|
13 | return $valeurs; |
---|
14 | } |
---|
15 | |
---|
16 | function formulaires_jouer_composer_verifier_dist() { |
---|
17 | $erreurs = array(); |
---|
18 | return $erreurs; |
---|
19 | } |
---|
20 | |
---|
21 | function formulaires_jouer_composer_traiter_dist() { |
---|
22 | $res = array( |
---|
23 | 'editable' => true |
---|
24 | ); |
---|
25 | |
---|
26 | $output = array(); |
---|
27 | $err = ""; |
---|
28 | |
---|
29 | if (_request('obtenir')) { |
---|
30 | list($output, $err) = composer_composer_obtenir(); |
---|
31 | } |
---|
32 | elseif (_request('self_update')) { |
---|
33 | list($output, $err) = composer_composer_self_update(); |
---|
34 | } |
---|
35 | elseif (_request('update')) { |
---|
36 | list($output, $err) = composer_composer_update(); |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | if ($err) { |
---|
41 | $res['message_erreur'] = "Erreur survenue : $err"; |
---|
42 | } else { |
---|
43 | $res['message_ok'] = "Opération réussie"; |
---|
44 | } |
---|
45 | |
---|
46 | if (count($output)) { |
---|
47 | $res['message_output'] = implode("\n", $output); |
---|
48 | set_request('message_output', $res['message_output']); |
---|
49 | } |
---|
50 | |
---|
51 | return $res; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Télécharge composer |
---|
56 | * |
---|
57 | * @return array Liste (sorties, erreur) |
---|
58 | **/ |
---|
59 | function composer_composer_obtenir() { |
---|
60 | sous_repertoire(_DIR_COMPOSER); |
---|
61 | $root = realpath(_DIR_COMPOSER); |
---|
62 | chdir($root); |
---|
63 | $home = "export COMPOSER_HOME=" . _ROOT_RACINE . "tmp"; |
---|
64 | $cmd = "$home && curl -sS https://getcomposer.org/installer | php 2>&1"; |
---|
65 | exec($cmd, $output, $err); |
---|
66 | if (!$err) { |
---|
67 | exec("chmod 775 composer.phar", $output, $err); |
---|
68 | } |
---|
69 | chdir(_ROOT_CWD); |
---|
70 | return array($output, $err); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Met à jour composer.phar |
---|
75 | * |
---|
76 | * @return array Liste (sorties, erreur) |
---|
77 | **/ |
---|
78 | function composer_composer_self_update() { |
---|
79 | return composer_composer_run('self-update'); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Met à jour les libs composer |
---|
84 | * |
---|
85 | * @return array Liste (sorties, erreur) |
---|
86 | **/ |
---|
87 | function composer_composer_update() { |
---|
88 | return composer_composer_run('update'); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Exécute la commande indiquée par composer. |
---|
93 | * |
---|
94 | * @return array Liste (sorties, erreur) |
---|
95 | **/ |
---|
96 | function composer_composer_run($commande) { |
---|
97 | $root = realpath(_DIR_COMPOSER); |
---|
98 | chdir($root); |
---|
99 | $home = "export COMPOSER_HOME=" . _ROOT_RACINE . "tmp"; |
---|
100 | $cmd = "$home && php composer.phar $commande 2>&1"; |
---|
101 | exec($cmd, $output, $err); |
---|
102 | chdir(_ROOT_CWD); |
---|
103 | return array($output, $err); |
---|
104 | } |
---|