Initial commit
This commit is contained in:
56
src/ImageReference.php
Normal file
56
src/ImageReference.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user