-
Notifications
You must be signed in to change notification settings - Fork 0
/
composer-fast-update.php
executable file
·39 lines (31 loc) · 1.03 KB
/
composer-fast-update.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
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
$args = array_reverse($argv);
$version = array_shift($args);
$package_name = array_shift($args);
print 'Update: ' . $package_name . ' - ' . $version . PHP_EOL;
if (empty($package_name) || empty($version)) {
return;
}
$filepath = $_SERVER['PWD'] . '/composer.lock';
$composer_lock = json_decode(file_get_contents($filepath), TRUE);
$write = FALSE;
if (isset($composer_lock['packages'])) {
foreach ($composer_lock['packages'] as &$package) {
if ($package['name'] == $package_name) {
$git_url = $package['source']['url'];
$output = shell_exec('git ls-remote ' . $git_url . ' ' . $version);
$hash = substr($output, 0, 40);
print $hash . PHP_EOL;
$package['source']['reference'] = $hash;
$package['time'] = date('Y-m-d H:i:s');
$write = TRUE;
}
}
}
if ($write) {
file_put_contents($filepath, json_encode($composer_lock, 448 & 128));
$file = new \Composer\Json\JsonFile($filepath);
$file->write($composer_lock);
}