예제 #1
1
파일: Wash.php 프로젝트: pean/wash
 protected function hashids($type, $str)
 {
     $hashids = new \Hashids\Hashids(md5($this->config['salt']));
     if ($type == 'decode') {
         return end($hashids->decode($str));
     } elseif ($type == "encode") {
         return $hashids->encode($str);
     }
 }
예제 #2
0
파일: WashTests.php 프로젝트: pean/wash
 public function testHashidsDecode()
 {
     $hash = 'Jn';
     $hashids = new \Hashids\Hashids(md5($this->config['salt']));
     $id = end($hashids->decode($hash));
     $method = new ReflectionMethod($this->wash, 'hashids');
     $method->setAccessible(TRUE);
     $wid = $method->invokeArgs($this->wash, array('decode', $hash));
     $this->assertEquals($id, $wid);
 }
예제 #3
0
파일: Tools.php 프로젝트: sheyooo/testify
 public static function decodeHashID($salt, $hash_id)
 {
     $hashids = new Hashids\Hashids($salt, 10);
     $number = $hashids->decode($hash_id);
     //print_r($number);
     if (isset($number[0])) {
         return $number[0];
     } else {
         throw new Exception("Unable to decode hash_id");
     }
 }
function decodeSubscriber($subscriberHash)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.subscribers'), 20, config('gtw.hashid.hash_chars'));
    $ids = null;
    try {
        $ids = $hashids->decode($subscriberHash);
    } catch (\Exception $e) {
    }
    if (count($ids) == 0) {
        return null;
    }
    return Subscriber::findOrFail($ids[0]);
}
예제 #5
0
 public function decode_ids($data)
 {
     $hashids = new \Hashids\Hashids();
     return $hashids->decode($data);
 }
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object with custom alphabet */
$hashids = new Hashids\Hashids('this is my salt', 0, 'abcdefgh123456789');
/* encode several numbers into one id */
$id = $hashids->encode(1, 2, 3, 4);
/* decode the same id */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
예제 #7
0
<?php

require_once 'vendor/autoload.php';
// Change this to the number of ids you want to generate
$count = 10000;
$bench = new Ubench();
$bench->start();
$hashids = new Hashids\Hashids('4w3s0m3');
for ($i = 0; $i <= $count; $i++) {
    $encoded = $hashids->encode($i);
    // var_dump($encoded);
    $decoded = $hashids->decode($encoded);
}
$bench->end();
echo "\n# Hashids\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "\n============\n";
$bench->start();
$fakeId = new Guidsen\FakeIdentifier\Optimus(15468539, 1296427827, 340274557);
for ($i = 0; $i <= $count; $i++) {
    $encoded = $fakeId->encode($i);
    // var_dump($encoded);
    $decoded = $fakeId->decode($encoded);
}
$bench->end();
echo "\n# FakeIdentifier\n";
echo sprintf("Time: %s\n", $bench->getTime());
echo "============\n\n";