| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * PHP Client for DDN Web Object Scalar (WOS) API | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @package Wosclient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author  Casey McLaughlin <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @license http://opensource.org/licenses/MIT MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @link    https://github.com/caseyamcl/wosclient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * ------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | namespace WosClient\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * WOS Exceptions are thrown when the WOS returns error codes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Specifically, non-0 x-ddn-status HTTP headers are translated to this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Casey McLaughlin <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class WosServerException extends WosException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     const UNKNOWN_NAME    = 'UNKNOWN'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     const UNKNOWN_MEANING = 'Unknown or undocumented WOS error code returned'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * Code Names Map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var array|string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private static $codeNames  = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         200 => 'NoNodeForPolicy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         201 => 'NoNodeForObject', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         202 => 'UnknownPolicyName', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         203 => 'InternalError', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         205 => 'InvalidObjId', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         206 => 'NoSpace', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         207 => 'ObjNotFound', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         208 => 'ObjCorrupted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         209 => 'FsCorrupted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         210 => 'PolicyNotSupported', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         211 => 'IOErr', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         212 => 'InvalidObjectSize', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         214 => 'TemporarilyNotSupported', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         216 => 'ReservationNotFound', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         217 => 'EmptyObject', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         218 => 'InvalidMetadataKey', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         219 => 'UnusedReservation', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         220 => 'WireCorruption', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         221 => 'CommandTimeout', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         222 => 'InvalidGetSpan' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * Code Meanings Map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @var array|string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     private static $codeMeanings = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         200 => 'No nodes will accept Put or Reserve operations for this policy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         201 => 'No nodes have a copy of the requested object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         202 => 'Policy name or id is not currently supported by the cluster', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         203 => 'Unknown internal Error', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         205 => 'An invalid OID was specified', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         206 => 'The cluster is full', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         207 => 'Object cannot be located', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         208 => 'Object does not match its checksum', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         209 => 'Filesystem internal structures are corrupted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         210 => 'Insufficient cluster resources to service Put or Reserve request for this policy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         211 => 'Unrecoverable drive error', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         212 => '> 5 TB', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         214 => 'Operation should be retried momentarily', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         216 => 'Reservation not found for specified OID', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         217 => 'Attempt to store a zero-length object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         218 => 'Invalid metadata key specified', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         219 => 'Attempted Get of an unused reservation', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         220 => 'Uncorrectable network corruption of the object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         221 => 'Command did not complete in a timely manner', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         222 => 'Illegal combination of buffered=true, integity=false' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     // --------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * WosServerException constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param string     $code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param string     $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param \Exception $previous | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     public function __construct($code, $message = '', \Exception $previous = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         // If we get a '0' from the server, and we throw this exception, then | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         // something is wrong in this codebase. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         if ($code == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             throw new \LogicException('0 DDN code is not an error code (it is the success code)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         // Automatically set message if not specified | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         if (! $message) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             $message = array_key_exists($code, static::$codeMeanings) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 ? static::$codeMeanings[$code] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 : static::UNKNOWN_MEANING; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         parent::__construct($message, $code, $previous); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * Get DDN error name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     public function getErrorName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         return array_key_exists($this->getCode(), static::$codeNames) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ? static::$codeNames[$this->getCode()] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             : static::UNKNOWN_NAME; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * Get the DDN error meaning | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |     public function getErrorMeaning() | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |         return array_key_exists($this->getCode(), static::$codeMeanings) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |             ? static::$codeMeanings[$this->getCode()] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             : static::UNKNOWN_MEANING; | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     public function __toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         return sprintf('%s %s: %s', $this->getCode(), $this->getErrorName(), $this->getErrorMeaning()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 145 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 146 |  |  |  | 
            
                        
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: