* animated gif and camera urls are moved to funService

This commit is contained in:
Dávid Danyi 2017-09-08 17:52:27 +02:00
parent 0b7f357c29
commit dfcd3b086e
8 changed files with 120 additions and 17 deletions

View File

@ -33,3 +33,4 @@ $app->get('/api/kanban', App\Action\KanbanAction::class, 'api.kanban');
$app->get('/avatars/{signum}', App\Action\AvatarAction::class, 'user.avatar');
$app->get('/api/tsp-info', App\Action\TspInfoAction::class, 'api.tsp-info');
$app->get('/api/want-some-fun', App\Action\FunAction::class, 'api.fun');

View File

@ -0,0 +1,32 @@
<?php
namespace App\Action;
use App\Response\JsonCorsResponse;
use App\Service\FunService;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
class FunAction implements ServerMiddlewareInterface
{
/**
* @var FunService
*/
private $tspInfoService;
public function __construct(FunService $tspInfoService)
{
$this->tspInfoService = $tspInfoService;
}
/**
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
* @return JsonCorsResponse
*/
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
return new JsonCorsResponse($this->tspInfoService->getSomeFun());
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Action;
use App\Service\FunService;
use Interop\Container\ContainerInterface;
class FunFactory
{
public function __invoke(ContainerInterface $container)
{
$funService = $container->get(FunService::class);
return new FunAction($funService);
}
}

View File

@ -46,7 +46,8 @@ class ConfigProvider
Action\AvatarAction::class => Action\AvatarFactory::class,
Action\HomePageAction::class => Action\HomePageFactory::class,
Action\KanbanAction::class => Action\KanbanFactory::class,
Action\TspInfoAction::class => Action\TspInfoFactory::class,
Action\TspInfoAction::class => Action\TspInfoFactory::class,
Action\FunAction::class => Action\FunFactory::class,
Service\AvatarService::class => Service\AvatarServiceFactory::class,
Service\JiraCollectorService::class => Service\JiraCollectorServiceFactory::class,
@ -55,6 +56,7 @@ class ConfigProvider
Service\TrInfoCollectorService::class => Service\TrInfoCollectorServiceFactory::class,
Service\JcatInfoCollectorService::class => Service\JcatInfoCollectorServiceFactory::class,
Service\TspInfoService::class => Service\TspInfoServiceFactory::class,
Service\FunService::class => Service\FunServiceFactory::class,
'service.cache' => function(ContainerInterface $container): StorageInterface {
$cache = new FilesytemCache();

View File

@ -0,0 +1,50 @@
<?php
namespace App\Service;
use Zend\Cache\Storage\StorageInterface;
use Zend\Config\Config;
class FunService
{
const CACHE_KEY = 'funPage';
/**
* @var StorageInterface
*/
private $cache;
/**
* @var Config
*/
private $config;
public function __construct(
StorageInterface $cache,
Config $config
)
{
$this->cache = $cache;
$this->config = $config;
}
/**
* @param bool $forceReload
* @return array
*/
public function getSomeFun(bool $forceReload = false): array
{
$tspInfo = $this->cache->getItem(self::CACHE_KEY);
if($forceReload || null == $tspInfo) {
$tspInfo = [
'cameraUrls' => $this->config->get('url.eurestCameras')->toArray(),
'animGifs' => [],
];
$this->cache->setItem(self::CACHE_KEY, serialize($tspInfo));
} else {
$tspInfo = unserialize($tspInfo);
}
return $tspInfo;
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Service;
use Interop\Container\ContainerInterface;
use Zend\Config\Config;
class FunServiceFactory
{
public function __invoke(ContainerInterface $container)
{
$appConfig = $container->get('config')['app.config'];
$cache = $container->get('service.cache');
return new FunService(
$cache,
new Config($appConfig)
);
}
}

View File

@ -2,12 +2,7 @@
namespace App\Service;
use League\Csv\Reader;
use League\Csv\Statement;
use Zend\Cache\Storage\StorageInterface;
use Zend\Config\Config;
use Zend\Http\Client;
use Zend\Json\Json;
class TspInfoService
{
@ -19,11 +14,6 @@ class TspInfoService
*/
private $cache;
/**
* @var Config
*/
private $config;
/**
* @var VacationInfoCollectorService
*/
@ -51,7 +41,6 @@ class TspInfoService
public function __construct(
StorageInterface $cache,
Config $config,
VacationInfoCollectorService $vacationInfoCollectorService,
TrInfoCollectorService $trInfoCollectorService,
JcatInfoCollectorService $jcatInfoCollectorService,
@ -60,7 +49,6 @@ class TspInfoService
)
{
$this->cache = $cache;
$this->config = $config;
$this->vacationInfoCollectorService = $vacationInfoCollectorService;
$this->trInfoCollectorService = $trInfoCollectorService;
$this->jcatInfoCollectorService = $jcatInfoCollectorService;
@ -77,8 +65,6 @@ class TspInfoService
$tspInfo = $this->cache->getItem(self::CACHE_KEY);
if($forceReload || null == $tspInfo) {
$tspInfo = [
'cameraUrls' => $this->config->get('url.eurestCameras')->toArray(),
'animGifs' => [],
'praGoals' => $this->trInfoCollectorService->getPraGoals(),
'trProgressInfo' => $this->trInfoCollectorService->getProgressInfo(),
'trFlowErrors' => $this->jcatInfoCollectorService->getTrFlowErrors(),

View File

@ -10,7 +10,6 @@ class TspInfoServiceFactory
{
public function __invoke(ContainerInterface $container)
{
$appConfig = $container->get('config')['app.config'];
$cache = $container->get('service.cache');
$dataCollectorService = $container->get(VacationInfoCollectorService::class);
$trInfoCollectorService = $container->get(TrInfoCollectorService::class);
@ -19,7 +18,6 @@ class TspInfoServiceFactory
$jiraInfoCollectorService = $container->get(JiraCollectorService::class);
return new TspInfoService(
$cache,
new Config($appConfig),
$dataCollectorService,
$trInfoCollectorService,
$jcatInfoCollectorService,