Exemple #1
0
 /**
  * Generate a hashid based on random data.
  *
  * @param null $salt
  *
  * @return string
  */
 function generate_hashid($salt = null)
 {
     if (empty($salt)) {
         $salt = config('key');
     }
     $hashids = new Hashids($salt);
     $min = rand(1, 1000) * rand(1, 1000);
     $max = rand(1, 1000) * rand(1, 1000);
     $quantity = rand(1, 64);
     $numbers = unique_random_numbers_within_range($min, $max, $quantity);
     return StaticStringy::truncate(StaticStringy::shuffle($hashids->encode($numbers)), 8);
 }
 /**
  * @dataProvider truncateProvider()
  */
 public function testTruncate($expected, $str, $length, $substring = '', $encoding = null)
 {
     $result = S::truncate($str, $length, $substring, $encoding);
     $this->assertInternalType('string', $result);
     $this->assertEquals($expected, $result);
 }
Exemple #3
0
 public function truncate($string, $length, $ending = '...')
 {
     return Stringy::truncate($string, $length, $ending);
 }