progminer / maintenance-screen
The "Maintenance mode" screen library
Requires
- php: ^7.1
- progminer/util-template-renderer: ^1.0
- symfony/config: ^4.0
- symfony/http-foundation: ^4.0
Requires (Dev)
- phpunit/phpunit: ^7
- symfony/yaml: ^4.0
- twig/twig: ^2.4
Suggests
- symfony/yaml: To use the yaml file loader
- twig/twig: To use the twig template renderer
README
The "Maintenance mode" screen library
Install
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
Usage
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
.
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
.
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.
Todo
- Add more file loaders
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email eridan200@mail.ru instead of using the issue tracker.
Credits
API Documentation
This projects API documentation is built using Sami and available at https://progminer.github.io/maintenance-screen/master/.
Build
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.
License
The MIT License (MIT). Please see License File for more information.