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
<?php
/**
* No such entity service exception
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Exception;
use Magento\Framework\Phrase;
/**
* @api
* @since 100.0.2
*/
class NoSuchEntityException extends LocalizedException
{
/**
* @deprecated
*/
const MESSAGE_SINGLE_FIELD = 'No such entity with %fieldName = %fieldValue';
/**
* @deprecated
*/
const MESSAGE_DOUBLE_FIELDS = 'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value';
/**
* @param \Magento\Framework\Phrase $phrase
* @param \Exception $cause
* @param int $code
*/
public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0)
{
if ($phrase === null) {
$phrase = new Phrase('No such entity.');
}
parent::__construct($phrase, $cause, $code);
}
/**
* Helper function for creating an exception when a single field is responsible for finding an entity.
*
* @param string $fieldName
* @param string|int $fieldValue
* @return \Magento\Framework\Exception\NoSuchEntityException
*/
public static function singleField($fieldName, $fieldValue)
{
return new self(
new Phrase(
'No such entity with %fieldName = %fieldValue',
[
'fieldName' => $fieldName,
'fieldValue' => $fieldValue
]
)
);
}
/**
* Helper function for creating an exception when two fields are responsible for finding an entity.
*
* @param string $fieldName
* @param string|int $fieldValue
* @param string $secondFieldName
* @param string|int $secondFieldValue
* @return \Magento\Framework\Exception\NoSuchEntityException
*/
public static function doubleField($fieldName, $fieldValue, $secondFieldName, $secondFieldValue)
{
return new self(
new Phrase(
'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
[
'fieldName' => $fieldName,
'fieldValue' => $fieldValue,
'field2Name' => $secondFieldName,
'field2Value' => $secondFieldValue,
]
)
);
}
}