-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
mezzio-tooling
executable file
·84 lines (68 loc) · 2.58 KB
/
mezzio-tooling
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env php
<?php // @codingStandardsIgnoreFile
declare(strict_types=1);
namespace Mezzio;
if (false === ($paths = getenv('PATH'))) {
fwrite(STDERR, "No PATH environment provided; cannot execute.\n");
fwrite(STDERR, "Please manually run 'composer require --dev mezzio/mezzio-tooling'\n");
fwrite(STDERR, "or 'composer remove mezzio/mezzio-tooling'.\n");
exit(1);
}
$paths = explode(PATH_SEPARATOR, $paths);
$bins = ['composer', 'composer.bat', 'composer.cmd', 'composer.phar'];
$composer = false;
foreach ($paths as $path) {
foreach ($bins as $bin) {
$try = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, $bin);
if (file_exists($try)) {
$composer = $try;
break 2;
}
}
}
if (! $composer) {
fwrite(STDERR, "Unable to find composer, composer.bat, or composer.phar in your PATH.\n");
fwrite(STDERR, "Please manually run 'composer require --dev mezzio/mezzio-tooling'\n");
fwrite(STDERR, "or 'composer remove mezzio/mezzio-tooling', using the\n");
fwrite(STDERR, "appropriate path to your composer binary.\n");
exit(1);
}
$command = $argc > 1 ? $argv[1] : '';
$remove = false;
switch (strtolower($command)) {
case 'remove':
echo "Removing mezzio-tooling\n";
$remove = true;
$command = sprintf('%s remove --dev mezzio/mezzio-tooling', $composer);
break;
default:
echo "Installing mezzio-tooling\n";
$command = sprintf('%s require --dev mezzio/mezzio-tooling', $composer);
break;
}
system($command, $return);
if ($return !== 0) {
fwrite(STDERR, "\n\nRequested installation/removal failed; please check the logs above.\n");
exit($return);
}
if ($remove) {
exit(0);
}
$toolingPackage = sprintf('%s/vendor/mezzio/mezzio-tooling/composer.json', getcwd());
if (! file_exists($toolingPackage)) {
fwrite(STDERR, "\n\nInstalled tooling package, but unable to locate script information.\n");
fwrite(STDERR, "Check your installation, and follow the migration documentation to use the tooling.\n");
exit(1);
}
$composer = json_decode(file_get_contents($toolingPackage), true);
if (! isset($composer['bin'])) {
fwrite(STDERR, "\n\nInstalled tooling package, but package does not contain script information?\n");
fwrite(STDERR, "Check your installation, and follow the migration documentation to use the tooling.\n");
exit(1);
}
echo "\n\nTooling installed!\n";
echo "The following migration and development tools are now available:\n";
array_walk($composer['bin'], function ($script) {
printf("- ./vendor/%s\n", $script);
});
exit(0);