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.
- Removed any knowledge of collaborators from the models. - Added factories to create the models by the retrieved data from the API. - Added a Movie repository that is able to load an movie providing the client and id ( by calling the API segment and passing the data on to the factory ). - Starting to refactor some bits of the API segment, removing the ->api() function call in the client. ( For now I just added getMovieApi(), but the whole api() method will vanish ). - Added a GenericCollectionFactory to create collections of objects we don't care much about (yet) to filter or ...? - Created some extra submodels for Movies
- Loading branch information
1 parent
9859dbd
commit f067911
Showing
25 changed files
with
837 additions
and
369 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?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 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
// This is optional, but if you want lots of data this is the way. | ||
$append = new \Tmdb\Model\Movie\QueryParameter\AppendToResponse(array( | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::ALTERNATIVE_TITLES, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::CHANGES, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::CREDITS, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::IMAGES, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::KEYWORDS, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::LISTS, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::RELEASES, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::REVIEWS, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::SIMILAR_MOVIES, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRAILERS, | ||
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS, | ||
)); | ||
|
||
$repository = new \Tmdb\Repository\MovieRepository($client); | ||
$movie = $repository->load(87421, array($append)); | ||
|
||
echo $movie->getTitle() . "\n"; | ||
|
||
echo "Alternative Titles\n"; | ||
|
||
foreach($movie->getAlternativeTitles() as $title) { | ||
printf(" - %s [%s]\n", $title->getTitle(), $title->getIso31661()); | ||
} | ||
|
||
echo "Cast\n"; | ||
|
||
foreach($movie->getCredits()->getCast() as $person) { | ||
printf(" - %s as %s\n", $person->getName(), $person->getCharacter()); | ||
} | ||
|
||
echo "Crew\n"; | ||
|
||
foreach($movie->getCredits()->getCrew() as $person) { | ||
printf(" - %s as %s\n", $person->getName(), $person->getJob()); | ||
} | ||
|
||
echo "Images\n"; | ||
|
||
foreach($movie->getImages() as $image) { | ||
printf(" - %s\n", $image->getFilePath()); | ||
} | ||
|
||
echo "Genres\n"; | ||
|
||
foreach($movie->getGenres() as $genre) { | ||
printf(" - %s\n", $genre->getName()); | ||
} | ||
|
||
echo "Keywords\n"; | ||
|
||
foreach($movie->getKeywords() as $keyword) { | ||
printf(" - %s [%s]\n", $keyword->getName(), $keyword->getId()); | ||
} | ||
|
||
echo "Releases\n"; | ||
|
||
foreach($movie->getReleases() as $release) { | ||
printf(" - %s on %s\n", $release->getIso31661(), $release->getReleaseDate()); | ||
} | ||
|
||
echo "Translations\n"; | ||
|
||
foreach($movie->getTranslations() as $translation) { | ||
printf(" - %s\n", $translation->getName()); | ||
} | ||
|
||
echo "Trailers\n"; | ||
|
||
foreach($movie->getTrailers() as $trailer) { | ||
printf(" - %s\n", $trailer->getUrl()); | ||
} |
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
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,90 @@ | ||
<?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\Common; | ||
|
||
use Tmdb\Exception\RuntimeException; | ||
use Tmdb\Model\AbstractModel; | ||
|
||
class ObjectHydrator { | ||
/** | ||
* Hydrate the object with data | ||
* | ||
* @param AbstractModel $object | ||
* @param array $data | ||
* @return $this | ||
* @throws RuntimeException | ||
*/ | ||
public static function hydrate(AbstractModel $object, $data = array()) | ||
{ | ||
if (!empty($data)) { | ||
foreach ($data as $k => $v) { | ||
if (in_array($k, $object::$_properties)) { | ||
|
||
$method = self::camelize( | ||
sprintf('set_%s', $k) | ||
); | ||
|
||
if (!method_exists($object, $method)) { | ||
throw new RuntimeException(sprintf( | ||
'Trying to call method "%s" on "%s" but it does not exist or is private.', | ||
$method, | ||
get_class($object) | ||
)); | ||
} | ||
|
||
$object->$method($v); | ||
} | ||
} | ||
} | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* Transforms an under_scored_string to a camelCasedOne | ||
* | ||
* @see https://gist.github.com/troelskn/751517 | ||
* | ||
* @param $candidate | ||
* @return string | ||
*/ | ||
private function camelize($candidate) | ||
{ | ||
return lcfirst( | ||
implode('', | ||
array_map('ucfirst', | ||
array_map('strtolower', | ||
explode('_', $candidate | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Transforms a camelCasedString to an under_scored_one | ||
* | ||
* @see https://gist.github.com/troelskn/751517 | ||
* | ||
* @param $camelized | ||
* @return string | ||
*/ | ||
private function uncamelize($camelized) { | ||
return implode('_', | ||
array_map('strtolower', | ||
preg_split('/([A-Z]{1}[^A-Z]*)/', $camelized, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY) | ||
) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.