1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of WebHelper Parser. |
6
|
|
|
* |
7
|
|
|
* (c) James <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace WebHelper\Parser\Exception; |
13
|
|
|
|
14
|
|
|
use DomainException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Invalid configuration file content. |
18
|
|
|
* |
19
|
|
|
* @author James <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class InvalidConfigException extends DomainException implements ParserExceptionInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* the exception to throw if the configuration file results as an empty active config. |
25
|
|
|
* |
26
|
|
|
* @param string $file file pathname |
27
|
|
|
* |
28
|
|
|
* @return InvalidConfigException the exception to throw |
29
|
|
|
*/ |
30
|
2 |
|
public static function forEmptyConfig($file) |
31
|
|
|
{ |
32
|
2 |
|
return new self(sprintf( |
33
|
2 |
|
'File "%s" returns an empty configuration', |
34
|
|
|
$file |
35
|
2 |
|
), self::EMPTY_CONFIG); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* the exception to throw if a directive has no ending key. |
40
|
|
|
* |
41
|
|
|
* @param string $key a directive name |
42
|
|
|
* |
43
|
|
|
* @return InvalidConfigException the exception to throw |
44
|
|
|
*/ |
45
|
1 |
|
public static function forEndingKeyNotFound($key) |
46
|
|
|
{ |
47
|
1 |
|
return new self(sprintf( |
48
|
1 |
|
'No ending directive for %s', |
49
|
|
|
$key |
50
|
1 |
|
), self::BLOCK_DIRECTIVE_ERROR); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* the exception to throw if a simple directive does not match against the accepted syntax. |
55
|
|
|
* |
56
|
|
|
* @param string $line the line of the simple directive |
57
|
|
|
* |
58
|
|
|
* @return InvalidConfigException the exception to throw |
59
|
|
|
*/ |
60
|
1 |
|
public static function forSimpleDirectiveSyntaxError($line) |
61
|
|
|
{ |
62
|
1 |
|
return new self(sprintf( |
63
|
1 |
|
'Syntax error for the line "%s"', |
64
|
|
|
$line |
65
|
1 |
|
), self::SIMPLE_DIRECTIVE_ERROR); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|