diff --git a/config/routes.php b/config/routes.php index 9a12990..48c567a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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'); diff --git a/src/App/Action/FunAction.php b/src/App/Action/FunAction.php new file mode 100644 index 0000000..827de34 --- /dev/null +++ b/src/App/Action/FunAction.php @@ -0,0 +1,32 @@ +tspInfoService = $tspInfoService; + } + + /** + * @param ServerRequestInterface $request + * @param DelegateInterface $delegate + * @return JsonCorsResponse + */ + public function process(ServerRequestInterface $request, DelegateInterface $delegate) + { + return new JsonCorsResponse($this->tspInfoService->getSomeFun()); + } +} diff --git a/src/App/Action/FunFactory.php b/src/App/Action/FunFactory.php new file mode 100644 index 0000000..05b3452 --- /dev/null +++ b/src/App/Action/FunFactory.php @@ -0,0 +1,15 @@ +get(FunService::class); + return new FunAction($funService); + } +} diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 1634693..37e2deb 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -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(); diff --git a/src/App/Service/FunService.php b/src/App/Service/FunService.php new file mode 100644 index 0000000..25225e7 --- /dev/null +++ b/src/App/Service/FunService.php @@ -0,0 +1,50 @@ +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; + } +} diff --git a/src/App/Service/FunServiceFactory.php b/src/App/Service/FunServiceFactory.php new file mode 100644 index 0000000..4975bc1 --- /dev/null +++ b/src/App/Service/FunServiceFactory.php @@ -0,0 +1,19 @@ +get('config')['app.config']; + $cache = $container->get('service.cache'); + return new FunService( + $cache, + new Config($appConfig) + ); + } +} diff --git a/src/App/Service/TspInfoService.php b/src/App/Service/TspInfoService.php index 0004557..d15e529 100644 --- a/src/App/Service/TspInfoService.php +++ b/src/App/Service/TspInfoService.php @@ -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(), diff --git a/src/App/Service/TspInfoServiceFactory.php b/src/App/Service/TspInfoServiceFactory.php index 2e15fab..3821903 100644 --- a/src/App/Service/TspInfoServiceFactory.php +++ b/src/App/Service/TspInfoServiceFactory.php @@ -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,