-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTransformerException.php
More file actions
66 lines (59 loc) · 1.73 KB
/
Copy pathTransformerException.php
File metadata and controls
66 lines (59 loc) · 1.73 KB
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
64
65
66
<?php declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (C) 2017-2021 Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CleverAge\ProcessBundle\Exception;
/**
* Runtime error that should wrap any Transformation error
*
* @author Valentin Clavreul <vclavreul@clever-age.com>
* @author Vincent Chalnot <vchalnot@clever-age.com>
*/
class TransformerException extends \RuntimeException implements ProcessExceptionInterface
{
/** @var string */
protected $transformerCode;
/** @var string */
protected $targetProperty;
/**
* {@inheritDoc}
*/
public function __construct($transformerCode, $code = 0, \Throwable $previous = null)
{
$this->transformerCode = $transformerCode;
parent::__construct('', $code, $previous);
$this->updateMessage();
}
/**
* @param string $targetProperty
*/
public function setTargetProperty(string $targetProperty): void
{
$this->targetProperty = $targetProperty;
$this->updateMessage();
}
protected function updateMessage()
{
if (isset($this->targetProperty)) {
$m = sprintf(
"For target property '%s', transformation '%s' have failed",
$this->targetProperty,
$this->transformerCode
);
} else {
$m = sprintf(
"Transformation '%s' have failed",
$this->transformerCode
);
}
if ($this->getPrevious()) {
$m .= ": {$this->getPrevious()->getMessage()}";
}
$this->message = $m;
}
}