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.
Adding first state of config with simple use case of the image helper
- Loading branch information
1 parent
a897abe
commit c3926cc
Showing
9 changed files
with
292 additions
and
43 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
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,45 @@ | ||
<?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\Client; | ||
use Tmdb\Model\Common\Collection; | ||
use Tmdb\Model\Configuration; | ||
|
||
class ConfigurationFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
$config = new Configuration(); | ||
|
||
return parent::hydrate($config, $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function createCollection(array $data = array()) | ||
{ | ||
$collection = new Collection(); | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, self::create($item)); | ||
} | ||
|
||
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
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,70 @@ | ||
<?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; | ||
|
||
use Tmdb\Client; | ||
use Tmdb\Model\Common\Collection; | ||
|
||
class Configuration extends AbstractModel { | ||
|
||
/** | ||
* @var Collection | ||
*/ | ||
private $images; | ||
|
||
/** | ||
* @var Collection | ||
*/ | ||
private $change_keys; | ||
|
||
public static $_properties = array( | ||
'images', | ||
'change_keys', | ||
); | ||
|
||
/** | ||
* @param \Tmdb\Model\Common\Collection $change_keys | ||
* @return $this | ||
*/ | ||
public function setChangeKeys($change_keys) | ||
{ | ||
$this->change_keys = $change_keys; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Model\Common\Collection | ||
*/ | ||
public function getChangeKeys() | ||
{ | ||
return $this->change_keys; | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Model\Common\Collection $images | ||
* @return $this | ||
*/ | ||
public function setImages($images) | ||
{ | ||
$this->images = $images; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Model\Common\Collection | ||
*/ | ||
public function getImages() | ||
{ | ||
return $this->images; | ||
} | ||
} |
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,46 @@ | ||
<?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\Helper; | ||
|
||
use Tmdb\Model\Configuration; | ||
use Tmdb\Model\Image; | ||
|
||
class ImageHelper { | ||
|
||
private $config; | ||
|
||
public function __construct(Configuration $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function getImageConfiguration() | ||
{ | ||
return $this->config->getImages(); | ||
} | ||
|
||
public function getUrl(Image $image, $size = 'original') { | ||
$config = $this->getImageConfiguration(); | ||
|
||
return sprintf('%s%s%s', $config['base_url'] , $size, $image->getFilePath()); | ||
} | ||
|
||
public function getHtml(Image $image, $size = 'original') { | ||
return sprintf( | ||
'<img src="%s" height="%s" width="%s" />', | ||
$this->getUrl($image, $size), | ||
$image->getHeight(), | ||
$image->getWidth() | ||
); | ||
} | ||
} |
Oops, something went wrong.