2016-04-19 13:54:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace NoccyLabs\Hotfix\Hotfix;
|
|
|
|
|
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2016-12-11 21:36:27 +00:00
|
|
|
use NoccyLabs\Hotfix\Runner\RunnerFactory;
|
2016-04-19 13:54:03 +00:00
|
|
|
|
|
|
|
class Hotfix
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $header;
|
|
|
|
|
|
|
|
protected $body;
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
protected $signature;
|
2016-04-19 13:54:03 +00:00
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
protected $origin;
|
|
|
|
|
|
|
|
public function __construct($body, Header $header, Signature $signature, $origin)
|
2016-04-19 13:54:03 +00:00
|
|
|
{
|
|
|
|
$this->header = $header;
|
|
|
|
$this->body = $body;
|
2016-12-11 21:36:27 +00:00
|
|
|
$this->signature = $signature;
|
|
|
|
$this->origin = $origin;
|
2016-04-19 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
public function getHeader()
|
2016-04-19 20:55:09 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
return $this->header;
|
2016-04-19 20:55:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
public function getHash()
|
2016-04-19 13:54:03 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
return sha1($this->body);
|
2016-04-19 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
public function getSignature()
|
2016-12-02 14:23:03 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
return $this->signature;
|
2016-12-02 14:23:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
public function getBody()
|
2016-04-19 20:55:09 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
return $this->body;
|
2016-04-19 20:55:09 +00:00
|
|
|
}
|
2016-04-19 13:54:03 +00:00
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
protected function load($hotfix)
|
2016-04-19 13:54:03 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
if (strpos($hotfix, "\n---\n")===false) {
|
|
|
|
throw new \Exception("Hotfix is missing a proper header, is line endings wrong?");
|
2016-04-19 21:08:22 +00:00
|
|
|
}
|
2016-12-11 21:36:27 +00:00
|
|
|
list ($header, $body) = explode("\n---\n", $hotfix, 2);
|
|
|
|
$header = Yaml::parse($header);
|
|
|
|
|
|
|
|
$this->header = $header;
|
|
|
|
$this->body = $body;
|
2016-04-19 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:36:27 +00:00
|
|
|
|
|
|
|
public function apply()
|
2016-04-19 13:54:03 +00:00
|
|
|
{
|
2016-12-11 21:36:27 +00:00
|
|
|
$runner = RunnerFactory::createRunner($this);
|
|
|
|
$runner->apply();
|
2016-04-19 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|