load($hotfix); $this->signer = $signer[0]; $this->keyId = $signer[1]; } protected function load($hotfix) { if (strpos($hotfix, "\n---\n")===false) { throw new \Exception("Hotfix is missing a proper header, is line endings wrong?"); } list ($header, $body) = explode("\n---\n", $hotfix, 2); $header = Yaml::parse($header); $this->header = $header; $this->body = $body; } public function getBody() { return $this->body; } public function apply() { if (!array_key_exists('lang', $this->header)) { $lang = 'bash'; } else { $lang = strtolower($this->header['lang']); } $script = null; $head = null; $foot = null; switch ($lang) { case 'bash': $exec = "/bin/bash"; $head = file_get_contents(__DIR__."/../stubs/bash.stub"); break; case 'php': $exec = "/usr/bin/env php"; $head = "header['hotfix']); file_put_contents($tmpfile, $head."\n".$this->body."\n".$foot); passthru($exec." ".$tmpfile); unlink($tmpfile); } public function getRequirements() { if (!array_key_exists('for',$this->header)) { return []; } return $this->header['for']; } public function getSignedBy() { if (!$this->signer) { return null; } return sprintf("%s <%s>", $this->signer['uids'][0]['name'], $this->signer['uids'][0]['email'] ); } public function getKeyId() { return $this->keyId; } public function getName() { if (!array_key_exists('hotfix', $this->header)) { return "Untitled hotfix"; } return $this->header['hotfix']; } public function getInfo() { if (!array_key_exists('info', $this->header)) { return "No additional information"; } return $this->header['info']; } public function getAuthor() { if (!array_key_exists('author', $this->header)) { return "Unknown author"; } return $this->header['author']; } }