php-hotfix/src/Hotfix/Hotfix.php

67 lines
1.2 KiB
PHP

<?php
namespace NoccyLabs\Hotfix\Hotfix;
use Symfony\Component\Yaml\Yaml;
use NoccyLabs\Hotfix\Runner\RunnerFactory;
class Hotfix
{
protected $header;
protected $body;
protected $signature;
protected $origin;
public function __construct($body, Header $header, Signature $signature, $origin)
{
$this->header = $header;
$this->body = $body;
$this->signature = $signature;
$this->origin = $origin;
}
public function getHeader()
{
return $this->header;
}
public function getHash()
{
return sha1($this->body);
}
public function getSignature()
{
return $this->signature;
}
public function getBody()
{
return $this->body;
}
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 apply()
{
$runner = RunnerFactory::createRunner($this);
$runner->apply();
}
}