10 class Updater
implements Command
17 public function __construct() {
18 $this->args
= new Cli\
Args([
19 ["h", "help", "Display this help",
20 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG|Cli\Args
::HALT
],
21 ["v", "verbose", "More output",
22 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG
],
23 ["q", "quiet", "Less output",
24 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG
],
25 [null, "signature", "Show pharext signature",
26 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG|Cli\Args
::HALT
],
27 [null, "license", "Show pharext license",
28 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG|Cli\Args
::HALT
],
29 [null, "version", "Show pharext version",
30 Cli\Args
::OPTIONAL|Cli\Args
::SINGLE|Cli\Args
::NOARG|Cli\Args
::HALT
],
31 [0, "path", "Path to .ext.phar to update",
32 Cli\Args
::REQUIRED|Cli\Args
::MULTI
],
38 * @see \pharext\Command::run()
40 public function run($argc, array $argv) {
42 $prog = array_shift($argv);
43 foreach ($this->args
->parse(--$argc, $argv) as $error) {
47 if ($this->args
["help"]) {
54 foreach (["signature", "license", "version"] as $opt) {
55 if ($this->args
[$opt]) {
56 printf("%s\n", $this->metadata($opt));
60 } catch (\Exception
$e) {
61 $this->error("%s\n", $e->getMessage());
66 foreach ($this->args
->validate() as $error) {
71 if (!$this->args
["quiet"]) {
74 foreach ($errs as $err) {
75 $this->error("%s\n", $err);
78 if (!$this->args
["quiet"]) {
84 foreach ($this->args
[0] as $file) {
85 $info = new SplFileInfo($file);
87 while ($info->isLink()) {
88 $info = new SplFileInfo($info->getLinkTarget());
91 if ($info->isFile()) {
92 $this->updatePackage($info);
94 $this->error("File '%s' does not exist\n", $file);
100 private function replacePharext($temp) {
101 $phar = new Phar($temp, Phar
::CURRENT_AS_SELF
);
102 $phar->startBuffering();
104 $meta = $phar->getMetadata();
106 // replace current pharext files
107 $core = (new Task\BundleGenerator
)->run($this->verbosity());
108 $phar->buildFromIterator($core);
109 $stub = __DIR__
."/../pharext_installer.php";
110 (new Task\
PharStub($phar, $stub))->run($this->verbosity());
112 // check dependencies
113 foreach ($phar as $info) {
114 if (fnmatch("*.ext.phar*", $info->getBasename())) {
115 $this->updatePackage($info, $phar);
119 $phar->stopBuffering();
122 "version" => Metadata
::version(),
123 "header" => Metadata
::header(),
124 ] +
(array) $phar->getMetadata());
126 $this->info("Updated pharext version from '%s' to '%s'\n",
127 isset($meta["version"]) ?
$meta["version"] : "(unknown)",
128 $phar->getMetadata()["version"]);
131 private function updatePackage(SplFileInfo
$file, Phar
$phar = null) {
132 $this->info("Updating pharext core in '%s'...\n", basename($file));
134 $temp = new Tempname("update", substr(strstr($file, ".ext.phar"), 4));
136 if (!copy($file->getPathname(), $temp)) {
139 if (!chmod($temp, $file->getPerms())) {
143 $this->replacePharext($temp);
146 $phar->addFile($temp, $file);
147 } elseif (!rename($temp, $file->getPathname())) {