maintenance-screen
![Software License][ico-license]
![Total Downloads][ico-downloads], (*1)
The "Maintenance mode" screen library, (*2)
Install
Via Composer, (*3)
``` bash
composer require progminer/maintenance-screen, (*4)
For using some included classes you also need to install more requrements:
- For `MaintenanceScreen\FileLoader\YamlFileLoader` - [Symfony Yaml](http://symfony.com/doc/current/components/yaml):
```bash
composer require symfony/yaml ^4.0
- For
ProgMinerUtils\TemplateRenderer\TwigTemplateRenderer
- Twig:
composer require twig/twig ^2.4
Usage
An instance of MaintenanceScreen\MaintenanceScreen
consists of configurations array,
MaintenanceScreen\TranslatorProvider\TranslatorProviderInterface
instance
and ProgMinerUtils\TemplateRenderer\TemplateRendererInterface
instance., (*5)
This example step by step illustrates how works with the MaintenanceScreen\MaintenanceScreen
., (*6)
Example
In first order you have to write uses, include a vendor/autoload.php
(ommited), etc.
Also you could make configuration array for MaintenanceScreen\MaintenanceScreen
., (*7)
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), (*8)
A simple example for first method here:, (*9)
$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
., (*10)
Now you have to make a ProgMinerUtils\TemplateRenderer\TemplateRendererInterface
instance,
for example, ProgMinerUtils\TemplateRenderer\CallableTemplateRenderer
:, (*11)
$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:, (*12)
$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
:, (*13)
$response = $maintenanceScreen->render();
$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., (*14)
Todo
Contributing
Please see CONTRIBUTING for details., (*15)
Security
If you discover any security related issues, please email eridan200@mail.ru instead of using the issue tracker., (*16)
Credits
API Documentation
This projects API documentation is built using Sami
and available at https://progminer.github.io/maintenance-screen/master/., (*17)
Build
In order to build the documentation first get Sami as a phar file:, (*18)
# curl -O http://get.sensiolabs.org/sami.phar
composer install-sami
Next build the documentation:, (*19)
# 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:, (*20)
php -S 127.0.0.1:3000 -t docs
Then visit http://localhost:3000/master/ to view., (*21)
License
The MIT License (MIT). Please see License File for more information., (*22)