php-hotfix/src/Hotfix/Hotfix.php

67 lines
1.2 KiB
PHP
Raw Normal View History

2016-04-19 13:54:03 +00:00
<?php
namespace NoccyLabs\Hotfix\Hotfix;
use Symfony\Component\Yaml\Yaml;
use NoccyLabs\Hotfix\Runner\RunnerFactory;
2016-04-19 13:54:03 +00:00
class Hotfix
{
protected $header;
protected $body;
protected $signature;
2016-04-19 13:54:03 +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;
$this->signature = $signature;
$this->origin = $origin;
2016-04-19 13:54:03 +00:00
}
public function getHeader()
2016-04-19 20:55:09 +00:00
{
return $this->header;
2016-04-19 20:55:09 +00:00
}
public function getHash()
2016-04-19 13:54:03 +00:00
{
return sha1($this->body);
2016-04-19 13:54:03 +00:00
}
public function getSignature()
{
return $this->signature;
}
public function getBody()
2016-04-19 20:55:09 +00:00
{
return $this->body;
2016-04-19 20:55:09 +00:00
}
2016-04-19 13:54:03 +00:00
protected function load($hotfix)
2016-04-19 13:54:03 +00:00
{
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;
2016-04-19 13:54:03 +00:00
}
public function apply()
2016-04-19 13:54:03 +00:00
{
$runner = RunnerFactory::createRunner($this);
$runner->apply();
2016-04-19 13:54:03 +00:00
}
}