The "Maintenance mode" screen library
Via Composer
composer require progminer/maintenance-screen
For using some included classes you also need to install more requrements:
- For
MaintenanceScreen\FileLoader\YamlFileLoader
- Symfony Yaml:
composer require symfony/yaml ^4.0
- For
ProgMinerUtils\TemplateRenderer\TwigTemplateRenderer
- Twig:
composer require twig/twig ^2.4
An instance of MaintenanceScreen\MaintenanceScreen
consists of configurations array,
MaintenanceScreen\TranslatorProvider\TranslatorProviderInterface
instance
and ProgMinerUtils\TemplateRenderer\TemplateRendererInterface
instance.
This example step by step illustrates how works with the MaintenanceScreen\MaintenanceScreen
.
In first order you have to write uses, include a vendor/autoload.php
(ommited), etc.
Also you could make configuration array for MaintenanceScreen\MaintenanceScreen
.
use MaintenanceScreen\ConfigurationLoader;
use MaintenanceScreen\MaintenanceScreen;
use MaintenanceScreen\TranslatorProvider\ArrayTranslatorProvider;
use ProgMinerUtils\TemplateRenderer\CallableTemplateRenderer;
$config = [
'template_name' => 'Default', // template name, not required
'default_language' => 'en', // uses if Accept-Language is not provided, not required
'charset' => 'utf-8' // not required, charset for Response and TemplateRenderer
];
Here you have to make MaintenanceScreen\TranslatorProvider\TranslatorProviderInterface
instance
and you have two included methods:
- Use translations from array (
MaintenanceScreen\TranslatorProvider\ArrayTranslatorProvider
class) - Use translations from config files (
MaintenanceScreen\TranslatorProvider\FilesystemTranslatorProvider
class)
A simple example for first method here:
$translatorsProvider = new ArrayTranslatorProvider([
'en' => ['title' => 'Site in maintenance mode', 'text' => 'Site in maintenance mode'],
'ru' => ['title' => 'Сайт в режиме техобслуживания', 'text' => 'Сайт в режиме техобслуживания']
]);
Also you can create class that implements MaintenanceScreen\TranslatorProvider\ITranslatorProvider
.
Now you have to make a ProgMinerUtils\TemplateRenderer\TemplateRendererInterface
instance,
for example, ProgMinerUtils\TemplateRenderer\CallableTemplateRenderer
:
$templateRenderer = new CallableTemplateRenderer([
'Default' => function($vars) { ?>
<html lang="<?=$vars['lang']?>">
<head><title><?=$vars['title']?></title></head>
<body><h1><center><?=$vars['text']?></center></h1></body>
</html>
<?php }
]);
And, finally, MaintenanceScreen\MaintenanceScreen
instance:
$maintenanceScreen = new MaintenanceScreen($config, $translatorProvider, $templateRenderer);
When you have an instance of MaintenanceScreen\MaintenanceScreen
you can render and/or send rendered Symfony\Component\HttpFoundation\Response
:
- Rendering:
$response = $maintenanceScreen->render();
- Sending:
$maintenanceScreen->send();
Both methods have not required argument $request
- instance of class Symfony\Component\HttpFoundation\Request
.
If it is not provided this methods calls a Symfony\Component\HttpFoundation\Request::createFromGlobals
method for getting current request.
- Add more file loaders
Please see CONTRIBUTING for details.
If you discover any security related issues, please email eridan200@mail.ru instead of using the issue tracker.
This projects API documentation is built using Sami and available at https://progminer.github.io/maintenance-screen/master/.
In order to build the documentation first get Sami as a phar file:
# curl -O http://get.sensiolabs.org/sami.phar
composer install-sami
Next build the documentation:
# php sami.phar update sami-config.php
composer regen-docs
The API Documentation will be generated into the docs
folder.
If you would like to preview it locally you can easily do so
with the built-in PHP server:
php -S 127.0.0.1:3000 -t docs
Then visit http://localhost:3000/master/ to view.
The MIT License (MIT). Please see License File for more information.