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 1.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 bool $origin_exception To throw the exception in the .env |
33
|
|
|
* @param string $file The .env file |
34
|
|
|
* @param string $line The line of the value |
35
|
|
|
* @param int $line_num The line num of the value |
36
|
|
|
* |
37
|
|
|
* @return \M1\Env\Exception\ParseException The exception |
|
|
|
|
38
|
|
|
*/ |
39
|
15 |
|
public function __construct($message, $origin_exception = false, $file = null, $line = null, $line_num = null) |
40
|
|
|
{ |
41
|
15 |
|
$message = $this->createMessage($message, $file, $line, $line_num); |
42
|
|
|
|
43
|
15 |
|
if ($origin_exception) { |
44
|
3 |
|
parent::__construct($message, 0, 1, $file, $line_num); |
45
|
3 |
|
} |
46
|
|
|
|
47
|
15 |
|
parent::__construct($message); |
48
|
15 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Constructs a ParseException message |
52
|
|
|
* |
53
|
|
|
* @param string $message The value to parse |
54
|
|
|
* @param string $file The .env file |
55
|
|
|
* @param string $line The line of the value |
56
|
|
|
* @param int $line_num The line num of the value |
57
|
|
|
* |
58
|
|
|
* @return string The exception message |
59
|
|
|
*/ |
60
|
15 |
|
private function createMessage($message, $file, $line, $line_num) |
61
|
|
|
{ |
62
|
15 |
|
if (!is_null($file)) { |
63
|
15 |
|
$message .= sprintf(" in %s", $file); |
64
|
15 |
|
} |
65
|
|
|
|
66
|
15 |
|
if (!is_null($line)) { |
67
|
15 |
|
$message .= sprintf(" near %s", $line); |
68
|
15 |
|
} |
69
|
|
|
|
70
|
15 |
|
if (!is_null($line_num)) { |
71
|
15 |
|
$message .= sprintf(" at line %d", $line_num); |
72
|
15 |
|
} |
73
|
|
|
|
74
|
15 |
|
return $message; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.