コード例 #1
0
ファイル: BaseHelperTest.php プロジェクト: rkubik/polr
 /**
  * Test BaseHelper
  *
  * @return void
  */
 private static function checkBaseGen($num)
 {
     $toBase32 = BaseHelper::toBase($num, 32);
     $toBase62 = BaseHelper::toBase($num, 62);
     $fromBase32 = BaseHelper::toBase10($toBase32, 32);
     $fromBase62 = BaseHelper::toBase10($toBase62, 62);
     if ($fromBase62 == $num && $fromBase32 == $num) {
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: LinkHelper.php プロジェクト: rkubik/polr
 public static function findSuitableEnding()
 {
     /**
      * Provided an in-use link ending (string),
      * find the next available base-32/62 ending.
      * @return string
      */
     $base = env('POLR_BASE');
     $link = Link::where('is_custom', 0)->orderBy('created_at', 'desc')->first();
     if ($link == null) {
         $base10_val = 0;
         $base_x_val = 0;
     } else {
         $latest_link_ending = $link->short_url;
         $base10_val = BaseHelper::toBase10($latest_link_ending, $base);
         $base10_val++;
     }
     $base_x_val = null;
     while (LinkHelper::linkExists($base_x_val) || $base_x_val == null) {
         $base_x_val = BaseHelper::toBase($base10_val, $base);
         $base10_val++;
     }
     return $base_x_val;
 }