forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Timezones first citizen, fixes php-tmdb#19.
- Loading branch information
1 parent
93842bb
commit d458133
Showing
8 changed files
with
1,744 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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\Factory; | ||
|
||
use Tmdb\Model\Collection\Timezones; | ||
use Tmdb\Model\Timezone; | ||
|
||
/** | ||
* Class TimezoneFactory | ||
* @package Tmdb\Factory | ||
*/ | ||
class TimezoneFactory extends AbstractFactory | ||
{ | ||
/** | ||
* @param array $data | ||
* | ||
* @return Timezone\CountryTimezone | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
return $this->hydrate(new Timezone\CountryTimezone(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new Timezones(); | ||
|
||
foreach ($data as $foobar_data) { | ||
foreach ($foobar_data as $iso_3166_1 => $timezones) { | ||
$country = new Timezone\CountryTimezone(); | ||
$country->setIso31661($iso_3166_1); | ||
|
||
foreach ($timezones as $timezone) { | ||
$country->getTimezones()->add(null, $timezone); | ||
} | ||
|
||
$collection->add(null, $country); | ||
} | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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\Collection; | ||
|
||
use Tmdb\Model\Common\GenericCollection; | ||
use Tmdb\Model\Timezone\CountryTimezone; | ||
|
||
/** | ||
* Class Timezones | ||
* @package Tmdb\Model\Collection | ||
*/ | ||
class Timezones extends GenericCollection | ||
{ | ||
/** | ||
* Returns all countries with timezones | ||
* | ||
* @return array | ||
*/ | ||
public function getCountries() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* Retrieve a country from the collection | ||
* | ||
* @param $id | ||
* @return CountryTimezone|null | ||
*/ | ||
public function getCountry($id) | ||
{ | ||
foreach ($this->data as $country) { | ||
if (strtoupper($id) == (string) $country) { | ||
return $country; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Add a timezone to the collection | ||
* | ||
* @param CountryTimezone $country | ||
*/ | ||
public function addCountry($country) | ||
{ | ||
$this->data[] = $country; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?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\Timezone; | ||
|
||
use Tmdb\Model\AbstractModel; | ||
use Tmdb\Model\Collection\Timezones; | ||
use Tmdb\Model\Common\GenericCollection; | ||
|
||
/** | ||
* Class Timezone | ||
* @package Tmdb\Model\Certification | ||
*/ | ||
class CountryTimezone extends AbstractModel | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $iso31661; | ||
|
||
/** | ||
* @var Timezones | ||
*/ | ||
private $timezones; | ||
|
||
public function __construct() | ||
{ | ||
$this->timezones = new GenericCollection(); | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Model\Collection\Timezones $timezones | ||
* @return $this | ||
*/ | ||
public function setTimezones($timezones) | ||
{ | ||
$this->timezones = $timezones; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Model\Collection\Timezones | ||
*/ | ||
public function getTimezones() | ||
{ | ||
return $this->timezones; | ||
} | ||
|
||
/** | ||
* @param string $iso31661 | ||
* @return $this | ||
*/ | ||
public function setIso31661($iso31661) | ||
{ | ||
$this->iso31661 = $iso31661; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getIso31661() | ||
{ | ||
return $this->iso31661; | ||
} | ||
|
||
/** | ||
* Verify if a country supports a certain timezone | ||
* | ||
* @param $timezone | ||
* @return mixed | ||
*/ | ||
public function supports($timezone) | ||
{ | ||
return false !== $this->timezones->hasValue($timezone); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->iso31661; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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\Repository; | ||
|
||
use Tmdb\Factory\TimezoneFactory; | ||
use Tmdb\Model\Collection\Timezones; | ||
|
||
/** | ||
* Class TimezoneRepository | ||
* @package Tmdb\Repository | ||
* @see http://docs.themoviedb.apiary.io/#timezones | ||
*/ | ||
class TimezoneRepository extends AbstractRepository | ||
{ | ||
/** | ||
* Get the list of supported timezones for the API methods that support them. | ||
* | ||
* @param $parameters | ||
* @param $headers | ||
* @return Timezones | ||
*/ | ||
public function getTimezones(array $parameters = array(), array $headers = array()) | ||
{ | ||
$data = $this->getApi()->getTimezones($this->parseQueryParameters($parameters), $headers); | ||
|
||
return $this->getFactory()->createCollection($data); | ||
} | ||
|
||
/** | ||
* Return the Collection API Class | ||
* | ||
* @return \Tmdb\Api\Timezones | ||
*/ | ||
public function getApi() | ||
{ | ||
return $this->getClient()->getTimezonesApi(); | ||
} | ||
|
||
/** | ||
* @return TimezoneFactory | ||
*/ | ||
public function getFactory() | ||
{ | ||
return new TimezoneFactory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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\Tests\Factory; | ||
|
||
use Tmdb\Factory\TimezoneFactory; | ||
use Tmdb\Model\Timezone\CountryTimezone; | ||
|
||
class TimezoneFactoryTest extends TestCase | ||
{ | ||
private $data; | ||
|
||
public function setUp() | ||
{ | ||
$this->data = $this->loadByFile('timezones/get.json'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldConstructTimezones() | ||
{ | ||
/** | ||
* @var TimezoneFactory $factory | ||
*/ | ||
$factory = $this->getFactory(); | ||
$timezonesCollection = $factory->createCollection($this->data); | ||
|
||
$this->assertInstanceOf('Tmdb\Model\Collection\Timezones', $timezonesCollection); | ||
|
||
/** | ||
* @var CountryTimezone $countryTimezone | ||
*/ | ||
foreach ($timezonesCollection as $countryTimezone) { | ||
$this->assertInstanceOf('Tmdb\Model\Timezone\CountryTimezone', $countryTimezone); | ||
$this->assertNotEmpty($countryTimezone->getIso31661()); | ||
|
||
foreach ($countryTimezone->getTimezones() as $timezone) { | ||
$this->assertNotEmpty($timezone); | ||
} | ||
} | ||
} | ||
|
||
protected function getFactoryClass() | ||
{ | ||
return 'Tmdb\Factory\TimezoneFactory'; | ||
} | ||
} |
Oops, something went wrong.