aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/exception/metadata.php
blob: 93cc337f5560c2ab7e5d779f8f0df6052dbe6ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
*
* @package extension
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
 * Exception class for metadata
 */
class phpbb_exception_metadata extends LogicException
{
	const NOT_SET = 10001;
	const INVALID = 10002;
	const FILE_GET_CONTENTS = 10003;
	const JSON_DECODE = 10004;
	const FILE_DOES_NOT_EXIST = 10005;

	public function __construct($code, $field_name)
	{
		$this->code = $code;
		$this->field_name = $field_name;
	}

	public function __toString()
	{
		return sprintf($this->getErrorMessage(), $this->field_name);
	}

	public function getErrorMessage()
	{
		switch ($this->code)
		{
			case self::NOT_SET:
				return 'The "%s" meta field has not been set.';
			break;

			case self::INVALID:
				return 'The "%s" meta field is not valid.';
			break;

			case self::FILE_GET_CONTENTS:
				return 'file_get_contents failed on %s';
			break;

			case self::JSON_DECODE:
				return 'json_decode failed on %s';
			break;

			case self::FILE_DOES_NOT_EXIST:
				return 'Required file does not exist at %s';
			break;

			default:
				return 'An unexpected error has occurred.';
			break;
		}
	}
}