-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathExceptionHandlerBlock.php
63 lines (57 loc) · 1.62 KB
/
ExceptionHandlerBlock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
/**
* Class of a Exception Handler Block
*
* Block for default and maintenance mode. During layout loading process corrupted block (that throws exception)
* will be replaced with a "dummy" block. As result, page will be loaded without broken block.
*
* When calls from parent to child block occurred and the error appeared in the child block,
* all blocks chain would be removed.
*/
class ExceptionHandlerBlock implements BlockInterface
{
/**
* @var string
*/
protected $blockName;
/**
* @param string $blockName
*/
public function __construct($blockName = '')
{
$this->blockName = $blockName;
}
/**
* Throws an exception when parent block calls corrupted child block method
*
* @param string $method
* @param array $args
* @return void
* @throws LocalizedException
*/
public function __call($method, $args)
{
throw new LocalizedException(
new Phrase('The "%1" block threw an exception, and it can\'t be rendered.', [$this->blockName])
);
}
/**
* Declared in BlockInterface and also throws an exception
*
* @throws LocalizedException
* @return void
*/
public function toHtml()
{
throw new LocalizedException(
new Phrase('The "%1" block threw an exception, and it can\'t be rendered.', [$this->blockName])
);
}
}