-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHomePageHandler.php
More file actions
102 lines (89 loc) · 3.85 KB
/
HomePageHandler.php
File metadata and controls
102 lines (89 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
namespace App\Handler;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Mezzio\LaminasView\LaminasViewRenderer;
use Mezzio\Plates\PlatesRenderer;
use Mezzio\Router;
use Mezzio\Template\TemplateRendererInterface;
use Mezzio\Twig\TwigRenderer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class HomePageHandler implements RequestHandlerInterface
{
/** @var string */
private $containerName;
/** @var Router\RouterInterface */
private $router;
/** @var null|TemplateRendererInterface */
private $template;
public function __construct(
string $containerName,
Router\RouterInterface $router,
?TemplateRendererInterface $template = null
) {
$this->containerName = $containerName;
$this->router = $router;
$this->template = $template;
}
public function handle(ServerRequestInterface $request) : ResponseInterface
{
if ($this->template === null) {
return new JsonResponse([
'welcome' => 'Congratulations! You have installed the mezzio skeleton application.',
'docsUrl' => 'https://docs.mezzio.dev/mezzio/',
]);
}
$data = [];
switch ($this->containerName) {
case 'Aura\Di\Container':
$data['containerName'] = 'Aura.Di';
$data['containerDocs'] = 'http://auraphp.com/packages/2.x/Di.html';
break;
case 'Pimple\Container':
$data['containerName'] = 'Pimple';
$data['containerDocs'] = 'https://pimple.symfony.com/';
break;
case 'Laminas\ServiceManager\ServiceManager':
$data['containerName'] = 'Laminas Servicemanager';
$data['containerDocs'] = 'https://docs.laminas.dev/laminas-servicemanager/';
break;
case 'Auryn\Injector':
$data['containerName'] = 'Auryn';
$data['containerDocs'] = 'https://github.com/rdlowrey/Auryn';
break;
case 'Symfony\Component\DependencyInjection\ContainerBuilder':
$data['containerName'] = 'Symfony DI Container';
$data['containerDocs'] = 'https://symfony.com/doc/current/service_container.html';
break;
case 'Zend\DI\Config\ContainerWrapper':
case 'DI\Container':
$data['containerName'] = 'PHP-DI';
$data['containerDocs'] = 'http://php-di.org';
break;
}
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\LaminasRouter) {
$data['routerName'] = 'Laminas Router';
$data['routerDocs'] = 'https://docs.laminas.dev/laminas-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 LaminasViewRenderer) {
$data['templateName'] = 'Laminas View';
$data['templateDocs'] = 'https://docs.laminas.dev/laminas-view/';
}
return new HtmlResponse($this->template->render('app::home-page', $data));
}
}