Skip to content

Commit

Permalink
Listings OK
Browse files Browse the repository at this point in the history
Next, individual getters

Signed-off-by: Davis Peixoto <davis.peixoto@gmail.com>
  • Loading branch information
davispeixoto committed Jul 23, 2017
1 parent e0a1e28 commit b738e4f
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 2 deletions.
65 changes: 65 additions & 0 deletions src/BlogCore/Service/ListAuthors.php
@@ -0,0 +1,65 @@
<?php
/**
* Created by PhpStorm.
* User: davis
* Date: 7/23/17
* Time: 3:12 AM
*/

namespace DavisPeixoto\BlogCore\Service;


use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
use DavisPeixoto\BlogCore\Repository\AuthorRepository;
use Psr\Log\LoggerInterface;
use Exception;
use stdClass;

/**
* Class ListAuthors
* @package DavisPeixoto\BlogCore\Service
*/
class ListAuthors implements ServiceInterface
{
/**
* @var AuthorRepository
*/
private $authorRepository;

/**
* @var array
*/
private $filters;

/**
* @var LoggerInterface
*/
private $logger;

/**
* ListAuthors constructor.
* @param AuthorRepository $authorRepository
* @param array $filters
* @param LoggerInterface $logger
*/
public function __construct(AuthorRepository $authorRepository, Array $filters, LoggerInterface $logger)
{
$this->authorRepository = $authorRepository;
$this->filters = $filters;
$this->logger = $logger;
}

/**
* @return array|stdClass[]
*/
public function run(): array
{
try {
return $this->authorRepository->getList($this->filters);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}

return [];
}
}
52 changes: 51 additions & 1 deletion src/BlogCore/Service/ListPosts.php
Expand Up @@ -9,7 +9,57 @@
namespace DavisPeixoto\BlogCore\Service;


class ListPosts
use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
use DavisPeixoto\BlogCore\Repository\PostRepository;
use Psr\Log\LoggerInterface;
use Exception;
use stdClass;

/**
* Class ListPosts
* @package DavisPeixoto\BlogCore\Service
*/
class ListPosts implements ServiceInterface
{
/**
* @var PostRepository
*/
private $postRepository;

/**
* @var array
*/
private $filters;

/**
* @var LoggerInterface
*/
private $logger;

/**
* ListPosts constructor.
* @param PostRepository $postRepository
* @param array $filters
* @param LoggerInterface $logger
*/
public function __construct(PostRepository $postRepository, Array $filters, LoggerInterface $logger)
{
$this->postRepository = $postRepository;
$this->filters = $filters;
$this->logger = $logger;
}

/**
* @return array|stdClass[]
*/
public function run(): array
{
try {
return $this->postRepository->getList($this->filters);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}

return [];
}
}
52 changes: 51 additions & 1 deletion src/BlogCore/Service/ListTags.php
Expand Up @@ -9,7 +9,57 @@
namespace DavisPeixoto\BlogCore\Service;


class ListTags
use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
use DavisPeixoto\BlogCore\Repository\TagRepository;
use Psr\Log\LoggerInterface;
use Exception;
use stdClass;

/**
* Class ListTags
* @package DavisPeixoto\BlogCore\Service
*/
class ListTags implements ServiceInterface
{
/**
* @var TagRepository
*/
private $tagRepository;

/**
* @var array
*/
private $filters;

/**
* @var LoggerInterface
*/
private $logger;

/**
* ListTags constructor.
* @param TagRepository $tagRepository
* @param array $filters
* @param LoggerInterface $logger
*/
public function __construct(TagRepository $tagRepository, Array $filters, LoggerInterface $logger)
{
$this->tagRepository = $tagRepository;
$this->filters = $filters;
$this->logger = $logger;
}

/**
* @return array|stdClass[]
*/
public function run(): array
{
try {
return $this->tagRepository->getList($this->filters);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}

return [];
}
}
65 changes: 65 additions & 0 deletions src/BlogCore/Service/ListTrails.php
@@ -0,0 +1,65 @@
<?php
/**
* Created by PhpStorm.
* User: davis
* Date: 7/23/17
* Time: 3:12 AM
*/

namespace DavisPeixoto\BlogCore\Service;


use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
use DavisPeixoto\BlogCore\Repository\TrailRepository;
use Psr\Log\LoggerInterface;
use Exception;
use stdClass;

/**
* Class ListTrails
* @package DavisPeixoto\BlogCore\Service
*/
class ListTrails implements ServiceInterface
{
/**
* @var TrailRepository
*/
private $trailRepository;

/**
* @var array
*/
private $filters;

/**
* @var LoggerInterface
*/
private $logger;

/**
* ListTrails constructor.
* @param TrailRepository $trailRepository
* @param array $filters
* @param LoggerInterface $logger
*/
public function __construct(TrailRepository $trailRepository, Array $filters, LoggerInterface $logger)
{
$this->trailRepository = $trailRepository;
$this->filters = $filters;
$this->logger = $logger;
}

/**
* @return array|stdClass[]
*/
public function run(): array
{
try {
return $this->trailRepository->getList($this->filters);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}

return [];
}
}

0 comments on commit b738e4f

Please sign in to comment.