X-Git-Url: https://git.rapsys.eu/userbundle/blobdiff_plain/bab59a4b88a081a7a27a53b4559d74e63b68db92..8c7e4a997b0702644721f19aadc9cce12594ea20:/Utils/Slugger.php diff --git a/Utils/Slugger.php b/Utils/Slugger.php deleted file mode 100644 index f3d8e25..0000000 --- a/Utils/Slugger.php +++ /dev/null @@ -1,84 +0,0 @@ -secret = $container->getParameter('secret'); - - //Init rev array - $rev = array_flip(array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'), range('!', '~'))); - - //Set offset - $this->offset = array_reduce(str_split($this->secret), function ($res, $a) use ($rev) { return $res += $rev[$a]; }, count($this->secret)) % count($rev); - } - - //Short the string - public function short($string) { - //Return string - $ret = ''; - - //Alphabet - $alpha = array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'), range('!', '~')); - - //Reverse alphabet - $rev = array_flip($alpha); - - //Number characters - $count = count($alpha); - - //Iterate on each character - foreach(str_split($string) as $c) { - if (isset($rev[$c]) && isset($alpha[($rev[$c]+$this->offset)%$count])) { - $ret .= $alpha[($rev[$c]+$this->offset)%$count]; - } - } - - //Send result - return str_replace(array('+','/'), array('-','_'), base64_encode($ret)); - } - - //Unshort the string - public function unshort($string) { - //Return string - $ret = ''; - - //Alphabet - $alpha = array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'), range('!', '~')); - - //Reverse alphabet - $rev = array_flip($alpha); - - //Number characters - $count = count($alpha); - - //Iterate on each character - foreach(str_split(base64_decode(str_replace(array('-','_'), array('+','/'), $string))) as $c) { - if (isset($rev[$c]) && isset($alpha[($rev[$c]-$this->offset+$count)%$count])) { - $ret .= $alpha[($rev[$c]-$this->offset+$count)%$count]; - } - } - - //Send result - return $ret; - } - - //Crypt and base64uri encode string - public function hash($string) { - return str_replace(array('+','/'), array('-','_'), base64_encode(crypt($string, $this->secret))); - } - - //Convert string to safe slug - function slug($string) { - return preg_replace('/[\/_|+ -]+/', '-', strtolower(trim(preg_replace('/[^a-zA-Z0-9\/_|+ -]/', '', str_replace(array('\'', '"'), ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $string))), '-'))); - } - -}