Skip to content

Commit 90ba7bb

Browse files
authored
Cast exceptions
initially used in system/Entity.php
1 parent 7fd144f commit 90ba7bb

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php namespace CodeIgniter\Exceptions;
2+
3+
/**
4+
* Cast Exceptions.
5+
*/
6+
class CastException extends CriticalError
7+
{
8+
9+
/**
10+
* Error code
11+
* @var int
12+
*/
13+
protected $code = 3;
14+
15+
public static function forInvalidJsonFormatException(int $error)
16+
{
17+
if($error === JSON_ERROR_DEPTH)
18+
{
19+
throw new static(lang('Cast.jsonErrorDepth'));
20+
}
21+
else if($error == JSON_ERROR_STATE_MISMATCH)
22+
{
23+
throw new static(lang('Cast.jsonErrorStateMismatch'));
24+
}
25+
else if($error == JSON_ERROR_CTRL_CHAR)
26+
{
27+
throw new static(lang('Cast.jsonErrorCtrlChar'));
28+
}
29+
else if($error == JSON_ERROR_SYNTAX)
30+
{
31+
throw new static(lang('Cast.jsonErrorSyntax'));
32+
}
33+
else if($error == JSON_ERROR_UTF8)
34+
{
35+
throw new static(lang('Cast.jsonErrorUtf8'));
36+
}
37+
else
38+
{
39+
throw new static(lang('Cast.jsonErrorUnknown'));
40+
}
41+
42+
}
43+
44+
}

0 commit comments

Comments
 (0)