1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the m1\env library |
5
|
|
|
* |
6
|
|
|
* (c) m1 <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @package m1/env |
12
|
|
|
* @version 2.0.0 |
13
|
|
|
* @author Miles Croxford <[email protected]> |
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
15
|
|
|
* @license http://github.com/m1/env/blob/master/LICENSE.md |
16
|
|
|
* @link http://github.com/m1/env/blob/master/README.md Documentation |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace M1\Env\Exception; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Env ParseException |
23
|
|
|
* |
24
|
|
|
* @since 0.1.0 |
25
|
|
|
*/ |
26
|
|
|
class ParseException extends \ErrorException |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Constructs a ParseException |
30
|
|
|
* |
31
|
|
|
* @param string $message The value to parse |
32
|
|
|
* @param string $line The line of the value |
33
|
|
|
* @param int $line_num The line num of the value |
34
|
|
|
*/ |
35
|
21 |
|
public function __construct($message, $line = null, $line_num = null) |
36
|
|
|
{ |
37
|
21 |
|
$message = $this->createMessage($message, $line, $line_num); |
38
|
|
|
|
39
|
21 |
|
parent::__construct($message); |
40
|
21 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructs a ParseException message |
44
|
|
|
* |
45
|
|
|
* @param string $message The value to parse |
46
|
|
|
* @param string $line The line of the value |
47
|
|
|
* @param int $line_num The line num of the value |
48
|
|
|
* |
49
|
|
|
* @return string The exception message |
50
|
|
|
*/ |
51
|
21 |
|
private function createMessage($message, $line, $line_num) |
52
|
|
|
{ |
53
|
21 |
|
if (!is_null($line)) { |
54
|
21 |
|
$message .= sprintf(" near %s", $line); |
55
|
21 |
|
} |
56
|
|
|
|
57
|
21 |
|
if (!is_null($line_num)) { |
58
|
21 |
|
$message .= sprintf(" at line %d", $line_num); |
59
|
21 |
|
} |
60
|
|
|
|
61
|
21 |
|
return $message; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|