1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
closurewrapper.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Engine\ActionFilter;
4
5
6use Bitrix\Main\Application;
7use Bitrix\Main\Config\Configuration;
8use Bitrix\Main\Event;
9use Bitrix\Main\InvalidOperationException;
10use Closure;
11
12final class ClosureWrapper extends Base
13{
17 private $closure;
18
23 public function __construct(Closure $closure)
24 {
25 $this->closure = $closure->bindTo($this, $this);
26 parent::__construct();
27 }
28
32 public function onBeforeAction(Event $event)
33 {
34 $this->ensureClosure();
35
36 return \call_user_func($this->closure, $event);
37 }
38
42 public function onAfterAction(Event $event)
43 {
44 $this->ensureClosure();
45
46 return \call_user_func($this->closure, $event);
47 }
48
49 private function ensureClosure(): void
50 {
51 if ($this->closure === null)
52 {
53 $exception = new InvalidOperationException('Closure has "static" modifier and can\'t be used. Use non-static closure instead.');
54
55 $exceptionHandling = Configuration::getValue('exception_handling');
56 if (!empty($exceptionHandling['debug']))
57 {
58 Application::getInstance()->getExceptionHandler()->writeToLog($exception);
59 }
60
61 throw $exception;
62 }
63 }
64}
static getInstance()
Определения application.php:98
Определения event.php:5
$event
Определения prolog_after.php:141