Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3766039
D637.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D637.diff
View Options
diff --git a/src/DockerImage.php b/src/DockerImage.php
--- a/src/DockerImage.php
+++ b/src/DockerImage.php
@@ -2,6 +2,8 @@
namespace Keruald\DockerHub;
+use InvalidArgumentException;
+
abstract class DockerImage {
///
@@ -24,7 +26,7 @@
public $image;
///
- /// Constructor
+ /// Constructors
///
/**
@@ -38,6 +40,24 @@
$this->image = $image;
}
+ /**
+ * Initializes a new instance of a DockerImage object
+ * from the slash notation.
+ *
+ * @param string $image the full user image name (e.g. "acme/foo")
+ * @return DockerImage
+ *
+ * @throws InvalidArgumentException when image name doesn't contain a slash.
+ */
+ public static function loadFromSlashNotation ($image) {
+ if (strpos($image, '/') === false) {
+ throw new InvalidArgumentException("Image name doesn't contain a slash (/).");
+ }
+
+ $imageFragments = explode('/', $image, 2);
+ return new static(...$imageFragments);
+ }
+
///
/// Helper methods
///
diff --git a/tests/DockerHubImageTest.php b/tests/DockerHubImageTest.php
--- a/tests/DockerHubImageTest.php
+++ b/tests/DockerHubImageTest.php
@@ -16,6 +16,18 @@
$this->image = new DockerHubImage("acme", "foo");
}
+ public function testLoadFromSlashNotation () {
+ $slashNotationImage = DockerHubImage::loadFromSlashNotation("acme/foo");
+ $this->assertEquals($slashNotationImage, $this->image);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testLoadFromSlashNotationWithInvalidArgument () {
+ DockerHubImage::loadFromSlashNotation("foo");
+ }
+
public function testGetRegistryUrl () {
$this->assertSame(
"https://registry.hub.docker.com/u/acme/foo",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 16:09 (18 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258376
Default Alt Text
D637.diff (1 KB)
Attached To
Mode
D637: DockerImage::loadFromSlashNotation
Attached
Detach File
Event Timeline
Log In to Comment