Skip to content

Commit

Permalink
Implementing interfaces to indicate filter support on the various models
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 15, 2014
1 parent 0070d2f commit bae65e9
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 18 deletions.
20 changes: 11 additions & 9 deletions lib/Tmdb/Model/Collection/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
*/
namespace Tmdb\Model\Collection;

use Tmdb\Factory\ImageFactory;
use Tmdb\Model\Common\Collection;

use Tmdb\Model\Filter\ImageFilter;
use Tmdb\Model\Image;

class Images extends Collection {
Expand Down Expand Up @@ -63,7 +65,7 @@ public function filterPosters()
{
return $this->filter(
function($key, $value) {
if ($value instanceof Image\PosterImage) { return true; }
if ($value instanceof ImageFilter && $value instanceof Image\PosterImage) { return true; }
}
);
}
Expand All @@ -77,7 +79,7 @@ public function filterBackdrops()
{
return $this->filter(
function($key, $value) {
if ($value instanceof Image\BackdropImage) { return true; }
if ($value instanceof ImageFilter && $value instanceof Image\BackdropImage) { return true; }
}
);
}
Expand All @@ -91,7 +93,7 @@ public function filterProfile()
{
return $this->filter(
function($key, $value) {
if ($value instanceof Image\ProfileImage) { return true; }
if ($value instanceof ImageFilter && $value instanceof Image\ProfileImage) { return true; }
}
);
}
Expand All @@ -105,7 +107,7 @@ public function filterStills()
{
return $this->filter(
function($key, $value) {
if ($value instanceof Image\StillImage) { return true; }
if ($value instanceof ImageFilter && $value instanceof Image\StillImage) { return true; }
}
);
}
Expand All @@ -120,7 +122,7 @@ public function filterMaxWidth($width)
{
return $this->filter(
function($key, $value) use ($width) {
if ($value->getWidth() <= $width && $value->getWidth() !== null) { return true; }
if ($value instanceof ImageFilter && $value->getWidth() <= $width && $value->getWidth() !== null) { return true; }
}
);
}
Expand All @@ -135,7 +137,7 @@ public function filterMinWidth($width)
{
return $this->filter(
function($key, $value) use ($width) {
if ($value->getWidth() >= $width && $value->getWidth() !== null) { return true; }
if ($value instanceof ImageFilter && $value->getWidth() >= $width && $value->getWidth() !== null) { return true; }
}
);
}
Expand All @@ -150,7 +152,7 @@ public function filterMaxHeight($height)
{
return $this->filter(
function($key, $value) use ($height) {
if ($value->getHeight() <= $height && $value->getHeight() !== null) { return true; }
if ($value instanceof ImageFilter && $value->getHeight() <= $height && $value->getHeight() !== null) { return true; }
}
);
}
Expand All @@ -165,7 +167,7 @@ public function filterMinHeight($height)
{
return $this->filter(
function($key, $value) use ($height) {
if ($value->getHeight() >= $height && $value->getHeight() !== null) { return true; }
if ($value instanceof ImageFilter && $value->getHeight() >= $height && $value->getHeight() !== null) { return true; }
}
);
}
Expand All @@ -184,7 +186,7 @@ public function filterBestVotedImage()
* @var $image Image
*/
foreach($this as $image) {
if ($image->getVoteAverage() > $voteAverage) {
if ($image instanceof ImageFilter && $image->getVoteAverage() > $voteAverage) {
$voteAverage = $image->getVoteAverage();
$currentImage = $image;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Tmdb/Model/Common/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace Tmdb\Model\Common;

use Guzzle\Common\Collection as GuzzleCollection;
use Tmdb\Model\Filter\AdultFilter;
use Tmdb\Model\Filter\CountryFilter;
use Tmdb\Model\Filter\LanguageFilter;

class Collection extends GuzzleCollection {
protected $data = array();
Expand Down Expand Up @@ -70,7 +73,7 @@ public function filterLanguage($language = 'en')
{
return $this->filter(
function($key, $value) use ($language) {
if ($value->getIso6391() == $language) { return true; }
if ($value instanceof LanguageFilter && $value->getIso6391() == $language) { return true; }
}
);
}
Expand All @@ -85,7 +88,7 @@ public function filterCountry($country = 'US')
{
return $this->filter(
function($key, $value) use ($country) {
if ($value->getIso31661() == $country) { return true; }
if ($value instanceof CountryFilter && $value->getIso31661() == $country) { return true; }
}
);
}
Expand All @@ -100,7 +103,7 @@ public function filterAdult($adult = false)
{
return $this->filter(
function($key, $value) use ($adult) {
if ($value->getAdult() == $adult) { return true; }
if ($value instanceof AdultFilter && $value->getAdult() == $adult) { return true; }
}
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Tmdb/Model/Common/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
*/
namespace Tmdb\Model\Common;

class Country extends AbstractModel {
use Tmdb\Model\AbstractModel;
use Tmdb\Model\Filter\CountryFilter;

class Country extends AbstractModel implements CountryFilter {

private $iso31661;
private $name;
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Common/SpokenLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
namespace Tmdb\Model\Common;

class SpokenLanguage extends AbstractModel {
class SpokenLanguage extends AbstractModel implements LanguageFilter {

private $iso6391;
private $name;
Expand Down
3 changes: 2 additions & 1 deletion lib/Tmdb/Model/Common/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
namespace Tmdb\Model\Common;

use Tmdb\Model\AbstractModel;
use Tmdb\Model\Filter\LanguageFilter;

class Translation extends AbstractModel {
class Translation extends AbstractModel implements LanguageFilter {

private $iso6391;
private $name;
Expand Down
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Filter/AdultFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Filter;

interface AdultFilter {
public function getAdult();
}
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Filter/CountryFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Filter;

interface CountryFilter {
public function getIso31661();
}
16 changes: 16 additions & 0 deletions lib/Tmdb/Model/Filter/ImageFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Filter;

interface ImageFilter {
}
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Filter/LanguageFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Filter;

interface LanguageFilter {
public function getIso6391();
}
5 changes: 4 additions & 1 deletion lib/Tmdb/Model/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
*/
namespace Tmdb\Model;

class Image extends AbstractModel {
use Tmdb\Model\Filter\ImageFilter;
use Tmdb\Model\Filter\LanguageFilter;

class Image extends AbstractModel implements ImageFilter, LanguageFilter {

const FORMAT_POSTER = 'poster';
const FORMAT_BACKDROP = 'backdrop';
Expand Down
3 changes: 2 additions & 1 deletion lib/Tmdb/Model/Movie/AlternativeTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
namespace Tmdb\Model\Movie;

use Tmdb\Model\AbstractModel;
use Tmdb\Model\Filter\CountryFilter;

class AlternativeTitle extends AbstractModel {
class AlternativeTitle extends AbstractModel implements CountryFilter {

private $iso31661;
private $title;
Expand Down
3 changes: 2 additions & 1 deletion lib/Tmdb/Model/Movie/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
namespace Tmdb\Model\Movie;

use Tmdb\Model\AbstractModel;
use Tmdb\Model\Filter\CountryFilter;

class Release extends AbstractModel {
class Release extends AbstractModel implements CountryFilter {

private $iso31661;
private $certification;
Expand Down

0 comments on commit bae65e9

Please sign in to comment.