| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Soheilrt\AdobeConnectClient\Client\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DomainException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Soheilrt\AdobeConnectClient\Client\Exceptions\InvalidException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Soheilrt\AdobeConnectClient\Client\Exceptions\NoAccessException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Soheilrt\AdobeConnectClient\Client\Exceptions\NoDataException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Soheilrt\AdobeConnectClient\Client\Exceptions\TooMuchDataException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Validate the status code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | abstract class StatusValidate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private const STATUS_OK = 'ok'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private const STATUS_INVALID = 'invalid'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private const STATUS_NO_ACCESS = 'no-access'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private const STATUS_NO_DATA = 'no-data'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     private const STATUS_TOO_MUCH_DATA = 'too-much-data'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * Validate the status code and throw an exception if something is wrong. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param array $status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @throws InvalidException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @throws NoAccessException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @throws NoDataException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @throws TooMuchDataException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @throws DomainException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public static function validate(array $status) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         switch ($status['code']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             case self::STATUS_OK: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             case self::STATUS_INVALID: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 $invalid = $status[self::STATUS_INVALID]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 throw new InvalidException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     self::getExceptionMessage(self::STATUS_INVALID, $invalid['subcode'], $invalid['field']) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             case self::STATUS_NO_ACCESS: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 throw new NoAccessException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                     self::getExceptionMessage( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                         self::STATUS_NO_ACCESS, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                         $status[self::STATUS_NO_ACCESS]['subcode'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             case self::STATUS_NO_DATA: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 throw new NoDataException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                     self::getExceptionMessage(self::STATUS_NO_DATA) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             case self::STATUS_TOO_MUCH_DATA: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 throw new TooMuchDataException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                     self::getExceptionMessage(self::STATUS_TOO_MUCH_DATA) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         throw new DomainException('Status Code is Invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param string $statusCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param null|string $subCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param null|string $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return mixed|void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |     private static function getExceptionMessage($statusCode, $subCode = null, $field = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $codes = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |             self::STATUS_NO_DATA => | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |                 'There is no data available (in response to an action that would normally result in returning data). ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |                 'Usually indicates that there is no item with the ID you specified. ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |                 'To resolve the error, change the specified ID to that of an item that exists.', | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |             self::STATUS_TOO_MUCH_DATA => 'The action should have returned a single result but is actually returning ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                 'multiple results. For example, if there are multiple users with the same user name and password, ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |                 'and you call the login action using that user name and password as parameters, ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |                 'the system cannot determine which user to log you in as, so it returns a too-much-data error.', | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |             self::STATUS_NO_ACCESS => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |                 'account-expired' => 'The account has expired.', | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |                 'denied' => 'Based on the supplied credentials, you don’t have permission to call the action.', | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                 'no-login' => 'The user is not logged in. To resolve the error, log in (using the login action) ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |                     'before you make the call.', | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |                 'illegalparent' => 'The specified acl - id is not a seminar or an unknown issue occured while ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |                     'retrieving the quota for that seminar.', | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |                 'no-quota' => 'The account limits have been reached or exceeded.', | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |                 'not-available' => 'The required resource is unavailable.', | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |                 'not-secure' => 'You must use SSL to call this action.', | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |                 'pending-activation' => 'The account is not yet activated.', | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |                 'pending-license' => 'The account’s license agreement has not been settled.', | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |                 'sco-expired' => 'The course or tracking content has expired.', | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |                 'sco-not-started' => 'The meeting or course has not started.', | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |                 'valuelessthanorequal' => 'Value is not a valid integer or is greater than the allowed license quota ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |                     'for that seminar.', | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |             self::STATUS_INVALID => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |                 'duplicate' => 'The call attempted to add a duplicate item on %s in a context where uniqueness is ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |                     'required.', | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |                 'format' => 'passed %s parameter had the wrong format.', | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |                 'illegal-operation' => 'The requested operation on %s violates integrity rules ' . | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |                     '(for example, moving a folder into itself).', | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |                 'missing' => 'A required parameter %s  is missing.', | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |                 'no-such-item' => 'The requested %s does not exist.', | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |                 'range' => 'The value of %s is outside the permitted range of values.' | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |             ] | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         switch ($statusCode) { | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |             case self::STATUS_INVALID: | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |                 return sprintf($codes[self::STATUS_INVALID][$subCode], $field); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             case self::STATUS_NO_ACCESS: | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |                 return $codes[self::STATUS_NO_ACCESS][$subCode]; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             case self::STATUS_NO_DATA: | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |                 return $codes[self::STATUS_NO_DATA]; | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |             case self::STATUS_TOO_MUCH_DATA: | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |                 return $codes[self::STATUS_TOO_MUCH_DATA]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 148 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 149 |  |  |  |