diff --git a/.gitignore b/.gitignore index 1a5e850a..9f412858 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /phpunit /public_html /cache.properties +/tmdb.log diff --git a/composer.json b/composer.json index ccf4814d..11419c94 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "monolog/monolog": ">=1.7.0" }, "suggest": { - "doctrine/cache": "This library is required if you want to make use of caching features.", - "monolog/monolog": "This library is required if you want to make use of logging features." + "doctrine/cache": "Required if you want to make use of caching features.", + "monolog/monolog": "Required if you want to make use of logging features." }, "autoload": { "psr-0": { "Tmdb\\": "lib/" } diff --git a/lib/Tmdb/Helper/ImageHelper.php b/lib/Tmdb/Helper/ImageHelper.php index 6d2755f4..639fd9e9 100644 --- a/lib/Tmdb/Helper/ImageHelper.php +++ b/lib/Tmdb/Helper/ImageHelper.php @@ -41,48 +41,50 @@ public function getImageConfiguration() /** * Get the url for the image resource * - * @param Image $image - * @param string $size + * @param Image|string $image Either an instance of Image or the file_path + * @param string $size * @return string */ - public function getUrl(Image $image, $size = 'original') + public function getUrl($image, $size = 'original') { $config = $this->getImageConfiguration(); - return $config['base_url'] . $size . $image->getFilePath(); + return $config['base_url'] . $size . $image; } /** * Get an img html tag for the image in the specified size * - * @param Image $image - * @param string $size - * @param int|null $width - * @param int|null $height + * @param Image|string $image Either an instance of Image or the file_path + * @param string $size + * @param int|null $width + * @param int|null $height * @return string */ - public function getHtml(Image $image, $size = 'original', $width = null, $height = null) + public function getHtml($image, $size = 'original', $width = null, $height = null) { - if (null == $image->getFilePath()) { - return ''; - } + if ($image instanceof Image) { + if (null == $image->getFilePath()) { + return ''; + } - $aspectRatio = $image->getAspectRatio(); + $aspectRatio = $image->getAspectRatio(); - if (null !== $width && null == $height && $aspectRatio !== null) { - $height = round($width / $aspectRatio); - } + if (null !== $width && null == $height && $aspectRatio !== null) { + $height = round($width / $aspectRatio); + } - if (null !== $height && null == $width && $aspectRatio !== null) { - $width = round($height * $aspectRatio); - } + if (null !== $height && null == $width && $aspectRatio !== null) { + $width = round($height * $aspectRatio); + } - if (null == $width) { - $width = $image->getWidth(); - } + if (null == $width) { + $width = $image->getWidth(); + } - if (null == $height) { - $height = $image->getHeight(); + if (null == $height) { + $height = $image->getHeight(); + } } return sprintf( diff --git a/lib/Tmdb/Model/Image.php b/lib/Tmdb/Model/Image.php index 53020318..ad39392d 100644 --- a/lib/Tmdb/Model/Image.php +++ b/lib/Tmdb/Model/Image.php @@ -201,4 +201,14 @@ public function getWidth() { return $this->width; } + + /** + * Return the file path when casted to string + * + * @return mixed + */ + public function __toString() + { + return $this->getFilePath(); + } } diff --git a/lib/Tmdb/Model/Person/CastMember.php b/lib/Tmdb/Model/Person/CastMember.php index 129bbdd8..adca6dfe 100644 --- a/lib/Tmdb/Model/Person/CastMember.php +++ b/lib/Tmdb/Model/Person/CastMember.php @@ -35,8 +35,14 @@ class CastMember extends AbstractMember implements PersonInterface */ private $castId; + /** + * @var mixed + */ + private $creditId; + public static $properties = array( 'id', + 'credit_id', 'cast_id', 'name', 'character', @@ -100,4 +106,23 @@ public function getCastId() { return $this->castId; } + + /** + * @param mixed $creditId + * @return $this + */ + public function setCreditId($creditId) + { + $this->creditId = $creditId; + + return $this; + } + + /** + * @return mixed + */ + public function getCreditId() + { + return $this->creditId; + } } diff --git a/lib/Tmdb/Model/Person/CrewMember.php b/lib/Tmdb/Model/Person/CrewMember.php index bf53811b..9f5277fb 100644 --- a/lib/Tmdb/Model/Person/CrewMember.php +++ b/lib/Tmdb/Model/Person/CrewMember.php @@ -30,8 +30,14 @@ class CrewMember extends AbstractMember implements PersonInterface */ private $job; + /** + * @var mixed + */ + private $creditId; + public static $properties = array( 'id', + 'credit_id', 'name', 'department', 'job', @@ -75,4 +81,23 @@ public function getJob() { return $this->job; } + + /** + * @param mixed $creditId + * @return $this + */ + public function setCreditId($creditId) + { + $this->creditId = $creditId; + + return $this; + } + + /** + * @return mixed + */ + public function getCreditId() + { + return $this->creditId; + } } diff --git a/test/Tmdb/Tests/Helper/ImageHelperTest.php b/test/Tmdb/Tests/Helper/ImageHelperTest.php index ae3864b8..eb123ca8 100644 --- a/test/Tmdb/Tests/Helper/ImageHelperTest.php +++ b/test/Tmdb/Tests/Helper/ImageHelperTest.php @@ -127,4 +127,27 @@ public function shouldBeEmptyIfFilePathIsNotGiven() $this->assertEquals('', $this->helper->getHtml($image)); } + + /** + * @test + */ + public function shouldGetImageUrlByString() + { + $imageUrl = $this->helper->getUrl('/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg'); + + $this->assertEquals('http://image.tmdb.org/t/p/original/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg', $imageUrl); + } + + /** + * @test + */ + public function shouldGetImageElementByString() + { + $imageUrl = $this->helper->getHtml('/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg'); + + $this->assertEquals( + '', + $imageUrl + ); + } }