1 <?php
2 /**
3 * MyAllocator BuildToUs PHP SDK Error Object
4 *
5 * @package myallocator/myallocator-php-sdk-ota
6 * @author Nathan Helenihi <support@myallocator.com>
7 * @copyright Copyright (c) MyAllocator
8 * @license http://mit-license.org/
9 * @link https://github.com/MyAllocator/myallocator-php-sdk-ota
10 */
11
12 namespace MyAllocator\phpsdkota\src\Object;
13
14 class MaError
15 {
16 /**
17 * @var integer The error id.
18 */
19 public $id = null;
20
21 /**
22 * @var string The error type.
23 */
24 public $type = null;
25
26 /**
27 * @var string The error message
28 */
29 public $msg = null;
30
31 /**
32 * @var mixed The data to return (if any).
33 */
34 public $data = null;
35
36 /**
37 * @var mixed MA error mappings.
38 */
39 private $errors = null;
40
41 /**
42 * Class contructor.
43 */
44 public function __construct($id = null, $data = null)
45 {
46 // Load error definitions
47 $this->errors = require(dirname(__FILE__) . '/../Config/MaErrorTypes.php');
48
49 // Assign error by id
50 if (!$id || !isset($this->errors[$id])) {
51 $id = MA_OTA_ERR;
52 }
53
54 $this->id = $id;
55 $this->type = $this->errors[$id]['type'];
56 $this->msg = $this->errors[$id]['msg'];
57 if ($data) {
58 $this->data = $data;
59 }
60 }
61
62 /**
63 * Get error mappings.
64 *
65 * @return array Error mappings
66 */
67 public function getMappings()
68 {
69 return $this->errors;
70 }
71
72 /**
73 * Convert error object to an array.
74 *
75 * @return array Error in array format.
76 */
77 public function toArray()
78 {
79 return array(
80 'id' => $this->id,
81 'type' => $this->type,
82 'msg' => $this->msg,
83 'data' => $this->data
84 );
85 }
86 }
87