Created
May 18, 2014 19:15
-
-
Save sasajib/033d279fab252d5bbd57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php namespace Sasajib\Pavilion\Api\NewsHeap; | |
use Sasajib\Pavilion\Api\Contracts\RequestValidatorInterface; | |
use Sasajib\Pavilion\Api\NewsHeap\Contracts\PaginationTypeInterface; | |
class TypeFactory | |
{ | |
protected $types = [ | |
'top-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\Top', | |
'side-top-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\SideTop', | |
'normal-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\Normal', | |
'world-cup-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\WorldCup', | |
'featured-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\Featured', | |
'interview-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\Interview', | |
'most-viewed-news' => '\Sasajib\Pavilion\Api\NewsHeap\NewsType\MostViewed' | |
]; | |
/** | |
* @var \Sasajib\Pavilion\Api\Contracts\RequestValidatorInterface | |
*/ | |
private $validator; | |
/** | |
* @var Contracts\PaginationTypeInterface | |
*/ | |
private $paginatorModel; | |
public function __construct(RequestValidatorInterface $validator, PaginationTypeInterface $paginatorModel) | |
{ | |
$this->validator = $validator; | |
$this->paginatorModel = $paginatorModel; | |
} | |
public function getNewsType($input) | |
{ | |
$this->validator->validate($input, $this->getBundle()); | |
$newsModel = new $this->types[$input]; | |
$newsModel->setPaginationType($this->paginatorModel); | |
return $newsModel; | |
} | |
private function getBundle() | |
{ | |
return $this->types; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment