Created
May 18, 2014 19:20
-
-
Save sasajib/6ab18ff30488114fa2ae 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\Exceptions\DatabaseException; | |
use Sasajib\Pavilion\Api\Exceptions\RequestValidationException; | |
use Sasajib\Pavilion\Api\NewsHeap\Contracts\NewsResponseInterface; | |
class NewsHeap | |
{ | |
/** | |
* @var Contracts\NewsResponseInterface | |
*/ | |
private $response; | |
public function __construct(NewsResponseInterface $response) | |
{ | |
$this->response = $response; | |
} | |
public function getNews($slug) | |
{ | |
try { | |
$news = (new SingleNewsModel)->getSingleNews($slug); | |
return $this->response->showSingleNews($news); | |
} catch (DatabaseException $e) { | |
return $this->response->showDatabaseError($e); | |
} | |
} | |
public function getNewsCollection($newsType, $pagination) | |
{ | |
try { | |
$newsType = $this->getNewsType($newsType, $pagination); | |
$news = $newsType->getNews(); | |
return $this->response->showNewsCollection($news); | |
} catch (RequestValidationException $e) { | |
return $this->response->showValidationError($e); | |
} catch (DatabaseException $e) { | |
return $this->response->showDatabaseError($e); | |
} | |
} | |
private function getPaginatorModel($pagination) | |
{ | |
$paginatorFactory = new PaginationFactory(new PaginationValidator()); | |
return $paginatorFactory->getType($pagination); | |
} | |
/** | |
* @param $newsType | |
* @param $pagination | |
* @return mixed | |
*/ | |
private function getNewsType($newsType, $pagination) | |
{ | |
$newsTypeFactory = new TypeFactory( | |
(new TypeValidator()), | |
($this->getPaginatorModel($pagination)) | |
); | |
return $newsTypeFactory->getNewsType($newsType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment