Пример #1
0
 function test_convertToBase()
 {
     $check_str = "12345678900987654321";
     $base_16_chars = '0123456789abcdef';
     $base_62_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $result = FOX_math::convertToBase($check_str, $base_16_chars);
     $this->assertEquals($result, "ab54a98cdc6770b1");
     $result = FOX_math::convertToBase($check_str, $base_62_chars);
     $this->assertEquals($result, "eHZl6hFR4k1");
 }
 /**
  * Writes a multiple raw strings to the store 
  *
  * @version 1.0
  * @since 1.0
  *
  * @param mixed $value | single value	 
  * @return bool | Exception on failure. Array of prefixed hash keys on success.
  */
 public function setMulti($data)
 {
     $result = array();
     foreach ($data as $value) {
         // Values MUST be serialized to prevent (int)0, (bool)false, and
         // NULL from all mapping to the same key
         $s_value = serialize($value);
         // Converting from base_16 to base_62 format reduces the key length
         // by almost 50%, saving memory
         $hash_16 = md5($s_value);
         $hash_10 = FOX_math::convertFromBase($hash_16, $this->base_16_chars);
         $hash_62 = FOX_math::convertToBase($hash_10, $this->base_62_chars);
         // We add $this-prefix to each key to guarantee the key is still
         // a string in the event we get something like "0000000000000005"
         // back from convertToBase(). If we passed the value straight
         // through, PHP would set the 6th key in the array instead of the
         // named key "0000000000000005".
         $prefixed = $this->prefix . $hash_62;
         $this->store[$prefixed] = $s_value;
         $result[] = $prefixed;
     }
     unset($value);
     // We can't return as an array of $value => $hash because
     // its entirely possible we'll get things like "foo text string"
     // which isn't a valid associative array key
     return $result;
 }