-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExceptionDecorator.php
More file actions
44 lines (39 loc) · 992 Bytes
/
ExceptionDecorator.php
File metadata and controls
44 lines (39 loc) · 992 Bytes
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
<?php
/**
* Created by PhpStorm.
* User: milos
* Date: 17/09/17
* Time: 10:43
*/
class ExceptionDecorator
{
private $decoratedService;
private $exceptionHandler;
/**
* ExceptionDecorator constructor.
* @param $decoratedService
* @param $exceptionHandler
*/
public function __construct($decoratedService, $exceptionHandler)
{
$this->decoratedService = $decoratedService;
$this->exceptionHandler = $exceptionHandler;
}
/**
* @param string $name
* @param array $arguments
* @return mixed
* @throws \Exception
*/
public function __call($name, $arguments) {
if(!method_exists($this->decoratedService, $name)) {
throw new \Exception();
}
try {
$result = call_user_func_array([$this->decoratedService, $name], $arguments);
} catch(\Exception $ex) {
$this->exceptionHandler->handle($ex);
}
return $result;
}
}