protected function doRun()
{
if ($this->originDirectory === null) {
throw new exceptions\runtime($this->locale->_('Origin directory must be defined', $this->originDirectory));
}
if ($this->destinationDirectory === null) {
throw new exceptions\runtime($this->locale->_('Destination directory must be defined', $this->originDirectory));
}
if ($this->stubFile === null) {
throw new exceptions\runtime($this->locale->_('Stub file must be defined', $this->originDirectory));
}
if ($this->adapter->is_readable($this->originDirectory) === false) {
throw new exceptions\runtime($this->locale->_('Origin directory \'%s\' is not readable', $this->originDirectory));
}
if ($this->adapter->is_writable($this->destinationDirectory) === false) {
throw new exceptions\runtime($this->locale->_('Destination directory \'%s\' is not writable', $this->destinationDirectory));
}
if ($this->adapter->is_readable($this->stubFile) === false) {
throw new exceptions\runtime($this->locale->_('Stub file \'%s\' is not readable', $this->stubFile));
}
$pharFile = $this->destinationDirectory . DIRECTORY_SEPARATOR . self::phar;
@$this->adapter->unlink($pharFile);
$description = @$this->adapter->file_get_contents($this->originDirectory . DIRECTORY_SEPARATOR . 'ABOUT');
if ($description === false) {
throw new exceptions\runtime($this->locale->_('ABOUT file is missing in \'%s\'', $this->originDirectory));
}
$licence = @$this->adapter->file_get_contents($this->originDirectory . DIRECTORY_SEPARATOR . 'LICENSE');
if ($licence === false) {
throw new exceptions\runtime($this->locale->_('LICENSE file is missing in \'%s\'', $this->originDirectory));
}
$stub = @$this->adapter->file_get_contents($this->stubFile);
if ($stub === false) {
throw new exceptions\runtime($this->locale->_('Unable to read stub file \'%s\'', $this->stubFile));
}
$phar = call_user_func($this->pharFactory, $pharFile);
$phar['versions'] = serialize(array('1' => atoum\version, 'current' => '1'));
$phar->setStub($stub);
$phar->setMetadata(array('version' => atoum\version, 'author' => atoum\author, 'support' => atoum\mail, 'repository' => atoum\repository, 'description' => $description, 'licence' => $licence));
$phar->buildFromIterator(new iterators\recursives\atoum\source($this->originDirectory, '1'));
$phar->setSignatureAlgorithm(\phar::SHA1);
return $this;
}