3
3
namespace DataKit \DataViews \Data \Exception ;
4
4
5
5
use DataKit \DataViews \Data \DataSource ;
6
+ use DataKit \DataViews \Translation \Translator ;
6
7
use Throwable ;
7
8
8
9
/**
@@ -20,14 +21,23 @@ final class ActionForbiddenException extends DataSourceException {
20
21
*/
21
22
private DataSource $ data_source ;
22
23
24
+ /**
25
+ * The ID of the DataSet.
26
+ *
27
+ * @since $ve$
28
+ *
29
+ * @var string
30
+ */
31
+ private string $ id ;
32
+
23
33
/**
24
34
* @inheritDoc
25
35
*
26
36
* @since $ver$
27
37
*/
28
38
public function __construct (
29
39
DataSource $ data_source ,
30
- $ message = 'Action is forbidden. ' ,
40
+ $ message = 'datakit.action.forbidden ' ,
31
41
$ code = 403 ,
32
42
Throwable $ previous = null
33
43
) {
@@ -47,7 +57,10 @@ public function __construct(
47
57
* @return self The exception.
48
58
*/
49
59
public static function with_id ( DataSource $ data_source , string $ id ): self {
50
- return new self ( $ data_source , sprintf ( 'This action is forbidden for data set with id "%s". ' , $ id ) );
60
+ $ exception = new self ( $ data_source );
61
+ $ exception ->id = $ id ;
62
+
63
+ return $ exception ;
51
64
}
52
65
53
66
/**
@@ -60,4 +73,17 @@ public static function with_id( DataSource $data_source, string $id ): self {
60
73
public function data_source (): DataSource {
61
74
return $ this ->data_source ;
62
75
}
76
+
77
+ /**
78
+ * {@inheritDoc}
79
+ *
80
+ * @since $ver$
81
+ */
82
+ public function translate ( Translator $ translator ): string {
83
+ if ( ! isset ( $ this ->id ) ) {
84
+ return parent ::translate ( $ translator );
85
+ }
86
+
87
+ return $ translator ->translate ( 'datakit.action.forbidden.with_id ' , [ 'id ' => $ this ->id ] );
88
+ }
63
89
}
0 commit comments