@@ 22-65 (lines=44) @@ | ||
19 | * Class AbstractGetService |
|
20 | * @package DavisPeixoto\BlogCore\Service |
|
21 | */ |
|
22 | abstract class AbstractGetService implements ServiceInterface |
|
23 | { |
|
24 | /** |
|
25 | * @var RepositoryInterface |
|
26 | */ |
|
27 | protected $repository; |
|
28 | ||
29 | /** |
|
30 | * @var string |
|
31 | */ |
|
32 | protected $uuid; |
|
33 | ||
34 | /** |
|
35 | * @var LoggerInterface |
|
36 | */ |
|
37 | protected $logger; |
|
38 | ||
39 | /** |
|
40 | * AbstractGetService constructor. |
|
41 | * @param RepositoryInterface $repository |
|
42 | * @param string $uuid |
|
43 | * @param LoggerInterface $logger |
|
44 | */ |
|
45 | public function __construct(RepositoryInterface $repository, string $uuid, LoggerInterface $logger) |
|
46 | { |
|
47 | $this->repository = $repository; |
|
48 | $this->uuid = $uuid; |
|
49 | $this->logger = $logger; |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * @return stdClass|null |
|
54 | */ |
|
55 | public function run() |
|
56 | { |
|
57 | try { |
|
58 | return $this->repository->get($this->uuid); |
|
59 | } catch (Exception $e) { |
|
60 | $this->logger->error($e->getMessage()); |
|
61 | } |
|
62 | ||
63 | return null; |
|
64 | } |
|
65 | } |
|
66 |
@@ 22-65 (lines=44) @@ | ||
19 | * Class AbstractListService |
|
20 | * @package DavisPeixoto\BlogCore\Service |
|
21 | */ |
|
22 | abstract class AbstractListService implements ServiceInterface |
|
23 | { |
|
24 | /** |
|
25 | * @var RepositoryInterface |
|
26 | */ |
|
27 | protected $repository; |
|
28 | ||
29 | /** |
|
30 | * @var array |
|
31 | */ |
|
32 | protected $filters; |
|
33 | ||
34 | /** |
|
35 | * @var LoggerInterface |
|
36 | */ |
|
37 | protected $logger; |
|
38 | ||
39 | /** |
|
40 | * AbstractListService constructor. |
|
41 | * @param RepositoryInterface $repository |
|
42 | * @param array $filters |
|
43 | * @param LoggerInterface $logger |
|
44 | */ |
|
45 | public function __construct(RepositoryInterface $repository, array $filters, LoggerInterface $logger) |
|
46 | { |
|
47 | $this->repository = $repository; |
|
48 | $this->filters = $filters; |
|
49 | $this->logger = $logger; |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * @return stdClass[] |
|
54 | */ |
|
55 | public function run(): array |
|
56 | { |
|
57 | try { |
|
58 | return $this->repository->getList($this->filters); |
|
59 | } catch (Exception $e) { |
|
60 | $this->logger->error($e->getMessage()); |
|
61 | } |
|
62 | ||
63 | return []; |
|
64 | } |
|
65 | } |
|
66 |