Skip to content

Commit 464fc2c

Browse files
committed
Add UnavailableMiddleware
1 parent 2e53bae commit 464fc2c

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

config/autoload/dependencies.global.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Application::class => ApplicationFactory::class,
2121
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
2222
App\Middleware\AuthMiddleware::class => App\Middleware\AuthMiddlewareFactory::class,
23+
App\Middleware\UnavailableMiddleware::class => App\Middleware\UnavailableMiddlewareFactory::class,
2324
],
2425
],
2526
];

config/autoload/middleware-pipeline.global.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
// - pre-conditions
4141
// - modifications to outgoing responses
4242
Helper\ServerUrlMiddleware::class,
43+
App\Middleware\UnavailableMiddleware::class,
4344
App\Middleware\AuthMiddleware::class,
4445
],
4546
'priority' => PHP_INT_MAX,
@@ -67,4 +68,4 @@
6768
'priority' => -10000,
6869
],
6970
],
70-
];
71+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
4+
namespace App\Middleware;
5+
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use Zend\Diactoros\Response\HtmlResponse;
9+
10+
class UnavailableMiddleware
11+
{
12+
private $template;
13+
14+
public function __construct($template)
15+
{
16+
$this->template = $template;
17+
}
18+
19+
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
20+
{
21+
if (date('G') == '23' || (date('G') == '0' && date('i') < '30')) {
22+
return new HtmlResponse($this->template->render('app::unavailable'));
23+
}
24+
$response = $next($request, $response);
25+
return $response;
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
4+
namespace App\Middleware;
5+
6+
use Interop\Container\ContainerInterface;
7+
use Zend\Expressive\Template\TemplateRendererInterface;
8+
9+
class UnavailableMiddlewareFactory
10+
{
11+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
12+
{
13+
return new UnavailableMiddleware($container->get(TemplateRendererInterface::class));
14+
}
15+
}

templates/app/unavailable.html.twig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% set direction = 'rtl' %}
2+
{% extends '@layout/default.html.twig' %}
3+
4+
{% block title %}Unavailable{% endblock %}
5+
{% block content %}
6+
<h2 style="text-align: center;">
7+
با عرض پوزش سایت از ساعت 23:00 لغایت 00:30 در دسترسی نمی باشد
8+
</h2>
9+
{% endblock %}

0 commit comments

Comments
 (0)