<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Muzich\CoreBundle\Util;
use FOS\UserBundle\Util\CanonicalizerInterface;

class StrictCanonicalizer implements CanonicalizerInterface
{  
  public function remove_accent($texte)
  {
    $texte = mb_strtolower($texte, 'UTF-8');
    $texte = str_replace(
        array(
            'à', 'â', 'ä', 'á', 'ã', 'å',
            'î', 'ï', 'ì', 'í', 
            'ô', 'ö', 'ò', 'ó', 'õ', 'ø', 
            'ù', 'û', 'ü', 'ú', 
            'é', 'è', 'ê', 'ë', 
            'ç', 'ÿ', 'ñ', '\'', '"'
        ),
        array(
            'a', 'a', 'a', 'a', 'a', 'a', 
            'i', 'i', 'i', 'i', 
            'o', 'o', 'o', 'o', 'o', 'o', 
            'u', 'u', 'u', 'u', 
            'e', 'e', 'e', 'e', 
            'c', 'y', 'n', '', ''
        ),
        $texte
    );
 
    return $texte;        
  }
  
  public function canonicalize($string)
  {
    $string = mb_convert_case($string, MB_CASE_LOWER, mb_detect_encoding($string));
    // On retire les accents occidentaux.
    return $this->remove_accent($string);
  }
}
