File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Whitecube \LaravelFlexibleContent \Exceptions \Concerns ;
4
+
5
+ trait HasExtendableCodes
6
+ {
7
+ /**
8
+ * Add a new exception code to the existing array
9
+ *
10
+ * @param int $code
11
+ * @param string $message
12
+ * @return void
13
+ **/
14
+ static public function registerCode ($ code , $ message )
15
+ {
16
+ static ::$ codes [$ code ] = $ message ;
17
+ }
18
+
19
+ /**
20
+ * Get message for given exception code
21
+ *
22
+ * @param int $code
23
+ * @return null|string
24
+ **/
25
+ static public function getCodeMessage ($ code )
26
+ {
27
+ return static ::$ codes [$ code ] ?? null ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change 7
7
8
8
class InstanceNotInsertableException extends InvalidArgumentException
9
9
{
10
+ use Concerns \HasExtendableCodes;
11
+
10
12
/**
11
13
* The main refusal reason codes.
12
14
*
@@ -20,7 +22,7 @@ class InstanceNotInsertableException extends InvalidArgumentException
20
22
*
21
23
* @var array
22
24
**/
23
- static public $ reasons = [
25
+ static public $ codes = [
24
26
1 => 'Limit reached ' ,
25
27
2 => 'Layout limit reached ' ,
26
28
];
@@ -34,7 +36,7 @@ class InstanceNotInsertableException extends InvalidArgumentException
34
36
*/
35
37
static public function make (Layout $ instance , $ code ) : InvalidArgumentException
36
38
{
37
- $ reason = static ::$ reasons [ $ code] ?? 'Unknown refusal reason ' ;
39
+ $ reason = static ::getCodeMessage ( $ code) ?? 'Unknown refusal reason ' ;
38
40
39
41
return new static ($ reason . ': Could not insert instance " ' . $ instance ->getId () . '" with key " ' . $ instance ->getKey () . '". ' , $ code );
40
42
}
You can’t perform that action at this time.
0 commit comments