1 <?php
2 /**
3 * Copyright (C) 2014 MyAllocator
4 *
5 * A copy of the LICENSE can be found in the LICENSE file within
6 * the root directory of this library.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * IN THE SOFTWARE.
25 */
26
27 namespace MyAllocator\phpsdk\src\Object;
28 use MyAllocator\phpsdk\src\Exception\ApiException;
29
30 /**
31 * The authentication class used to store authentication parameters
32 * to be used in one or more API requests.
33 */
34 class Auth
35 {
36 /**
37 * @var string The vendor id (Required without user credentials).
38 */
39 public $vendorId = null;
40
41 /**
42 * @var string The vendor password (Required without user credentials).
43 */
44 public $vendorPassword = null;
45
46 /**
47 * @var string The user id (Required without vendor credentials).
48 */
49 public $userId = null;
50
51 /**
52 * @var string The system user id.
53 */
54 public $PMSUserId = null;
55
56 /**
57 * @var string The user password (Required without vendor credentials).
58 */
59 public $userPassword = null;
60
61 /**
62 * @var string The user token (can store/use instead of username/password).
63 */
64 public $userToken = null;
65
66 /**
67 * @var string The MyAllocator property id.
68 */
69 public $propertyId = null;
70
71 /**
72 * @var string The system property id.
73 */
74 public $PMSPropertyId = null;
75
76 /**
77 * @var array API Authentication to property mappings.
78 */
79 private $authKeyMap = array(
80 'Auth/VendorId' => 'vendorId',
81 'Auth/VendorPassword' => 'vendorPassword',
82 'Auth/UserId' => 'userId',
83 'PMSUserId' => 'PMSUserId',
84 'Auth/UserPassword' => 'userPassword',
85 'Auth/UserToken' => 'userToken',
86 'Auth/PropertyId' => 'propertyId',
87 'PMSPropertyId' => 'PMSPropertyId'
88 );
89
90 /**
91 * Map an API authentication key to the Auth object's
92 * variable and return it.
93 *
94 * @param string $key The API authentication key.
95 *
96 * @return mixed The requested API variable.
97 *
98 * @throws MyAllocator\phpsdk\src\Exception\ApiException
99 */
100 public function getAuthKeyVar($key)
101 {
102 if (!isset($this->authKeyMap[$key])) {
103 $msg = 'Invalid Auth key requested: ' . $key;
104 throw new ApiException($msg);
105 }
106
107 $property = $this->authKeyMap[$key];
108 return $this->$property;
109 }
110
111 /**
112 * Get an authentication key by variable name.
113 *
114 * @param string $property The property/variable name.
115 *
116 * @return string The authentication key.
117 *
118 * @throws MyAllocator\phpsdk\src\Exception\ApiException
119 */
120 public function getAuthKeyByVar($property)
121 {
122 if (!($key = array_search($property, $this->authKeyMap))) {
123 $msg = 'Invalid Auth property requested: ' . $property;
124 throw new ApiException($msg);
125 }
126
127 return $key;
128 }
129 }
130