-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMismatchException.php
91 lines (74 loc) · 3.37 KB
/
MismatchException.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
START LICENSE AND COPYRIGHT
This file is part of ZfExtended library
Copyright (c) 2013 - 2021 Marc Mittag; MittagQI - Quality Informatics; All rights reserved.
Contact: http://www.MittagQI.com/ / service (ATT) MittagQI.com
This file may be used under the terms of the GNU LESSER GENERAL PUBLIC LICENSE version 3
as published by the Free Software Foundation and appearing in the file lgpl3-license.txt
included in the packaging of this file. Please review the following information
to ensure the GNU LESSER GENERAL PUBLIC LICENSE version 3.0 requirements will be met:
https://www.gnu.org/licenses/lgpl-3.0.txt
@copyright Marc Mittag, MittagQI - Quality Informatics
@author MittagQI - Quality Informatics
@license GNU LESSER GENERAL PUBLIC LICENSE version 3
https://www.gnu.org/licenses/lgpl-3.0.txt
END LICENSE AND COPYRIGHT
*/
namespace MittagQI\ZfExtended;
use Exception;
use ZfExtended_ErrorCodeException;
use ZfExtended_Logger;
use ZfExtended_ResponseExceptionTrait;
/**
* Since no access is mostly an ACL misconfiguration we leave logging enabled.
*/
class MismatchException extends ZfExtended_ErrorCodeException
{
use ZfExtended_ResponseExceptionTrait;
/**
* @var integer
*/
protected $httpReturnCode = 400;
/**
* By default, we log that as INFO, if created as response then the level is set to DEBUG
* @var integer
*/
protected $level = ZfExtended_Logger::LEVEL_INFO;
protected static array $localErrorCodes = [
'E2000' => 'Param "{0}" - is not given', // REQ
'E2001' => 'Value "{0}" of param "{1}" - is in invalid format', // REX
'E2002' => 'No object of type "{0}" was found by key "{1}"', // KEY
'E2003' => 'Wrong value', // EQL
'E2004' => 'Value "{0}" of param "{1}" - is not in the list of allowed values', // FIS
'E2005' => 'Value "{0}" of param "{1}" - is in the list of disabled values', // DIS
'E2006' => 'Value "{0}" of param "{1}" - is not unique. It should be unique.', // UNQ
'E2007' => 'Extension "{0}" of file "{1}" - is not in the list of allowed values', // EXT
'E2008' => 'Object of type "{0}" already exists having key "{1}"', // KEY (negation)
'E2009' => 'Value "{0}" of param "{1}" should be minimum "{2}"', // MIN
'E2010' => 'Value "{0}" of param "{1}" should be maximum "{2}"', // MAX
];
/**
* Overridden to use custom message if given
*/
public function __construct($errorCode, array $extra = [], Exception $previous = null)
{
// Call parent
parent::__construct($errorCode, $extra, $previous);
// If custom message is given
if ($extra['custom'] ?? 0) {
// Get that
$msg = $extra['custom'];
// Else get default one
} else {
$msg = $this->getMessage();
}
// If message have placeholders like {0}, {1}, {2} etc
if (preg_match('~{([0-9])}~', $msg)) {
// Replace those with values from $extra arg
$msg = preg_replace_callback('~{([0-9])}~', fn ($m) => $extra[$m[1]] ?? $m[1], $msg);
}
// Spoof msg
$this->setMessage($msg);
}
}