Skip to content

Commit

Permalink
ErrorHandlerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 31, 2021
1 parent 5941e7c commit 3120566
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/Interfaces/ErrorHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Prokl\ServiceProvider\Interfaces;

/**
* Interface ErrorHandlerInterface
* @package Prokl\ServiceProvider\Interfaces
*
* @since 31.07.2021
*/
interface ErrorHandlerInterface
{
/**
* Показать экран "The site is experiencing technical difficulties",
* но со своим текстом.
*
* @param string $errorMessage Текст сообщения.
*
* @return mixed
*/
public function die(string $errorMessage = '');
}
8 changes: 6 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Prokl\ServiceProvider\Bundles\BundlesLoader;
use Prokl\ServiceProvider\Framework\AutoconfigureConfig;
use Prokl\ServiceProvider\Framework\SymfonyCompilerPassBag;
use Prokl\ServiceProvider\Interfaces\ErrorHandlerInterface;
use Prokl\ServiceProvider\Services\AppKernel;
use Prokl\ServiceProvider\Utils\ErrorScreen;
use Prokl\ServiceProvider\Utils\Loaders\PhpLoaderSettingsBitrix;
Expand Down Expand Up @@ -128,7 +129,7 @@ class ServiceProvider
protected $bundles = [];

/**
* @var ErrorScreen $errorHandler Обработчик ошибок.
* @var ErrorHandlerInterface $errorHandler Обработчик ошибок.
*/
protected $errorHandler;

Expand Down Expand Up @@ -508,7 +509,10 @@ private function getContainerClass() : string

if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) {
throw new InvalidArgumentException(
sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment)
sprintf(
'The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.',
$this->environment
)
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Utils/ErrorScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Prokl\ServiceProvider\Utils;

use CMain;
use Prokl\ServiceProvider\Interfaces\ErrorHandlerInterface;
use RuntimeException;

/**
Expand All @@ -11,8 +12,9 @@
*
* @since 16.03.2021 Легкий рефакторинг.
* @since 23.03.2021 Упрощение.
* @since 31.07.2021 Имплементация ErrorHandlerInterface.
*/
class ErrorScreen
class ErrorScreen implements ErrorHandlerInterface
{
/** @const string ERROR_PAGE Тэг под замену текстом сообщения об ошибке. */
private const ERROR_MESSAGE_TAG = '%error_message%';
Expand Down

0 comments on commit 3120566

Please sign in to comment.