Files
Christoph M. Becker 4b1dbb58de Add type hints
Some are not as specific as they should be, and some may even be wrong,
but since these are only type hints (not type declarations) they won't
affect code execution, but rather provide some help to better understand
the code – for developers as well as tooling.
2024-08-25 20:12:43 +02:00

73 lines
1.4 KiB
PHP

<?php
namespace SDK\Build\Dependency;
use SDK\{Config, Exception, FileOps};
class Package
{
use FileOps;
/** @var string */
protected $name;
/** @var Series */
protected $series;
/** @var Fetcher */
protected $fetcher;
/** @var string */
protected $filepath;
public function __construct(string $name, Series $series, Fetcher $fetcher)
{/*{{{*/
$this->name = $name;
$this->series = $series;
$this->fetcher = $fetcher;
}/*}}}*/
public function getUri() : string
{/*{{{*/
$base = Config::getDepsBaseUri();
$branch_data = Config::getCurrentBranchData();
$arch = $this->series->getArch();
return "$base/{$branch_data['crt']}/$arch/{$this->name}";
}/*}}}*/
public function retrieve(string $path) : void
{/*{{{*/
$this->filepath = $path . DIRECTORY_SEPARATOR . $this->name;
$cont = $this->fetcher->getByUri($this->getUri());
$fd = fopen($this->filepath, "wb");
fwrite($fd, $cont);
fclose($fd);
}/*}}}*/
public function unpack(string $path) : void
{/*{{{*/
if (!$this->filepath || !file_exists($this->filepath)) {
throw new Exception("Invalid filepath '{$this->filepath}'");
}
$this->unzip($this->filepath, $path);
}/*}}}*/
public function cleanup() : void
{/*{{{*/
unlink($this->filepath);
}/*}}}*/
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/