MyAllocator PMS PHP SDK
  • Namespace
  • Class
  • Tree

Namespaces

  • MyAllocator
    • phpsdk
      • src
        • Api
        • Exception
        • Object
        • Util
  • PHP

Classes

  • Common
  • Requestor
  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\Util;
 28 use MyAllocator\phpsdk\src\Object\Auth;
 29 use MyAllocator\phpsdk\src\Exception\ApiException;
 30 
 31 /**
 32  * Common methods used in the SDK.
 33  */
 34 abstract class Common
 35 {
 36     /**
 37      * Get an auth object from the local ENV or test data.
 38      *
 39      * @param array $keys The authentication keys to set.
 40      * @param string $debug Enable debug.
 41      *
 42      * @return array(Auth, string) Authentication object and bool if pulled from ENV.
 43      *
 44      * @throws MyAllocator\phpsdk\src\Exception\ApiException If no keys supplied.
 45      */
 46     public static function getAuthEnv($keys = null, $debug = false)
 47     {
 48         if (!$keys) {
 49             $msg = 'Keys parameter is required. (Keys to set from env)';
 50             throw new ApiException($msg);
 51         }
 52 
 53         /*
 54          * Some tests require all parameters to be from environment.
 55          * Otherwise, they are skipped.
 56          */
 57         $env = true;
 58 
 59         /*
 60          * To use, export the required environment vars:
 61          *   export ma_vendorId=VALUE
 62          *   export ma_vendorPassword=VALUE
 63          *   export ma_userId=VALUE
 64          *   export ma_userPassword=VALUE
 65          *   export ma_userToken=VALUE
 66          *   export ma_propertyId=VALUE
 67          *   export ma_PMSUserId=VALUE
 68          *   export ma_PMSPropertyId=VALUE
 69          */
 70         foreach ($keys as $k) {
 71             if (!($$k = getenv('ma_'.$k))) {
 72                 // Key does not exist in environment, use test data
 73                 $$k = '111';
 74                 $env = false;
 75             }
 76         }
 77 
 78         $auth = new Auth();
 79         $auth->vendorId = isset($vendorId) ? $vendorId : null;
 80         $auth->vendorPassword = isset($vendorPassword) ? $vendorPassword : null;
 81         $auth->userId = isset($userId) ? $userId: null;
 82         $auth->userPassword = isset($userPassword) ? $userPassword : null;
 83         $auth->userToken = isset($userToken) ? $userToken : null;
 84         $auth->PMSUserId = isset($PMSUserId) ? $PMSUserId : null;
 85         $auth->propertyId = isset($propertyId) ? $propertyId : null;
 86         $auth->PMSPropertyId = isset($PMSPropertyId) ? $PMSPropertyId : null;
 87         $auth->debug = $debug;
 88 
 89         return array(
 90             'auth' => $auth,
 91             'from_env' => $env
 92         );
 93     }
 94 
 95     /**
 96      * Returns the name of a class using get_class with the namespaces stripped.
 97      *
 98      * @param object|string $object Object or Class Name to retrieve name
 99      *
100      * @return string Name of class with namespaces stripped
101      */
102     public static function getClassName($object = null)
103     {
104         if (!is_object($object) && !is_string($object)) {
105             return false;
106         }
107 
108         $class = explode('\\', (is_string($object) ? $object : get_class($object)));
109         return $class[count($class) - 1];
110     }
111 }
112 
MyAllocator PMS PHP SDK API documentation generated by ApiGen