Initial commit

This commit is contained in:
Dávid Danyi
2017-07-31 15:50:48 +02:00
commit 05f45e5153
44 changed files with 5668 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Action;
use App\Service\AvatarService;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\TextResponse;
class AvatarAction implements ServerMiddlewareInterface
{
private $avatarService;
public function __construct(AvatarService $avatarService)
{
$this->avatarService = $avatarService;
}
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$signum = $request->getAttribute('signum', false);
if(!$signum) {
return new EmptyResponse();
}
$avatarData = $this->avatarService->getAvatarData($signum);
return new TextResponse($avatarData, 200, [
'content-type' => 'image/png',
]);
}
}

View File

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

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\Router;
use Zend\Expressive\Template;
use Zend\Expressive\Plates\PlatesRenderer;
use Zend\Expressive\Twig\TwigRenderer;
use Zend\Expressive\ZendView\ZendViewRenderer;
class HomePageAction implements ServerMiddlewareInterface
{
private $router;
private $template;
public function __construct(Router\RouterInterface $router, Template\TemplateRendererInterface $template = null)
{
$this->router = $router;
$this->template = $template;
}
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
if (! $this->template) {
return new JsonResponse([
'welcome' => 'Congratulations! You have installed the zend-expressive skeleton application.',
'docsUrl' => 'https://docs.zendframework.com/zend-expressive/',
]);
}
$data = [];
if ($this->router instanceof Router\AuraRouter) {
$data['routerName'] = 'Aura.Router';
$data['routerDocs'] = 'http://auraphp.com/packages/2.x/Router.html';
} elseif ($this->router instanceof Router\FastRouteRouter) {
$data['routerName'] = 'FastRoute';
$data['routerDocs'] = 'https://github.com/nikic/FastRoute';
} elseif ($this->router instanceof Router\ZendRouter) {
$data['routerName'] = 'Zend Router';
$data['routerDocs'] = 'https://docs.zendframework.com/zend-router/';
}
if ($this->template instanceof PlatesRenderer) {
$data['templateName'] = 'Plates';
$data['templateDocs'] = 'http://platesphp.com/';
} elseif ($this->template instanceof TwigRenderer) {
$data['templateName'] = 'Twig';
$data['templateDocs'] = 'http://twig.sensiolabs.org/documentation';
} elseif ($this->template instanceof ZendViewRenderer) {
$data['templateName'] = 'Zend View';
$data['templateDocs'] = 'https://docs.zendframework.com/zend-view/';
}
return new HtmlResponse($this->template->render('app::home-page', $data));
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Action;
use Interop\Container\ContainerInterface;
use Zend\Expressive\Router\RouterInterface;
use Zend\Expressive\Template\TemplateRendererInterface;
class HomePageFactory
{
public function __invoke(ContainerInterface $container)
{
$router = $container->get(RouterInterface::class);
$template = $container->has(TemplateRendererInterface::class)
? $container->get(TemplateRendererInterface::class)
: null;
return new HomePageAction($router, $template);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Action;
use App\Service\DataCollectorService;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\JsonResponse;
class KanbanAction implements ServerMiddlewareInterface
{
private $dataCollector;
public function __construct(DataCollectorService $dataCollectorService)
{
$this->dataCollector = $dataCollectorService;
}
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$kanbanResult = $this->dataCollector->getKanbanBoard();
return new JsonResponse($kanbanResult);
}
}

View File

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

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
use Zend\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ServerRequestInterface;
class PingAction implements ServerMiddlewareInterface
{
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
return new JsonResponse(['ack' => time()]);
}
}