+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
+ private function extract($phar) {
+ $temp = (new Task\Extract($phar))->run($this->verbosity());
+ $this->cleanup[] = new Task\Cleanup($temp);
+ return $temp;
+ }
+
+ private function hooks(SplObjectStorage $phars) {
+ $hook = [];
+ foreach ($phars as $phar) {
+ if (isset($phar["pharext_package.php"])) {
+ $sdir = include $phar["pharext_package.php"];
+ if ($sdir instanceof SourceDir) {
+ $this->args->compile($sdir->getArgs());
+ $hook[] = $sdir;
+ }
+ }
+ }
+ return $hook;
+ }
+
+ private function load() {
+ $list = new SplObjectStorage();
+ $phar = extension_loaded("Phar")
+ ? new Phar(Phar::running(false))
+ : new Archive(PHAREXT_PHAR);
+ $temp = $this->extract($phar);
+
+ foreach ($phar as $entry) {
+ $dep_file = $entry->getBaseName();
+ if (fnmatch("*.ext.phar*", $dep_file)) {
+ $dep_phar = extension_loaded("Phar")
+ ? new Phar("$temp/$dep_file")
+ : new Archive("$temp/$dep_file");
+ $list[$dep_phar] = $this->extract($dep_phar);
+ }
+ }
+
+ /* the actual ext.phar at last */
+ $list[$phar] = $temp;
+ return $list;