56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace NoccyLabs\FreshDocker;
|
|
|
|
|
|
class ImageReference
|
|
{
|
|
private $image;
|
|
|
|
private $tag;
|
|
|
|
private $registry;
|
|
|
|
private $scheme;
|
|
|
|
public function __construct(string $image)
|
|
{
|
|
// if (!preg_match('/^http[s]:\/\//i', $image)) {
|
|
$parts = explode("/", $image);
|
|
if (count($parts) < 3) {
|
|
$image = "https://registry.hub.docker.com/{$image}";
|
|
} else {
|
|
$image = "https://{$image}";
|
|
}
|
|
|
|
$parts = parse_url($image);
|
|
$image = ltrim($parts['path'],'/');
|
|
if (str_contains($image,':')) {
|
|
[$image, $tag] = explode(":", $image, 2);
|
|
} else {
|
|
$tag = 'latest';
|
|
}
|
|
if (!str_contains($image,'/')) {
|
|
$image = "library/{$image}";
|
|
}
|
|
$this->image = $image;
|
|
$this->tag = $tag;
|
|
$this->registry = $parts['host'];
|
|
$this->scheme = $parts['scheme'];
|
|
}
|
|
|
|
public function getRegistry(): string
|
|
{
|
|
return $this->registry;
|
|
}
|
|
|
|
public function getImage(): string
|
|
{
|
|
return $this->image;
|
|
}
|
|
|
|
public function getTag(): string
|
|
{
|
|
return $this->tag;
|
|
}
|
|
} |