<commit_before><?php
namespace NyroDev\UtilityBundle\Services;

class MainService extends AbstractService {
	
	
    /**
     * Generates a URL from the given parameters, allowing extra parameters (like comma)
     *
     * @param  string  $name       The name of the route
     * @param  mixed   $parameters An array of parameters
     * @param  Boolean $absolute   Whether to generate an absolute URL
     * @return string The generated URL
     */
	public function generateUrl($name, $parameters = array(), $absolute = false) {
		if ($name == '#')
			return '#';
		return str_replace('%2C', ',', $this->get('router')->generate($name, $parameters, $absolute));
	}
	
	public function getFullUrl($path) {
		$request = $this->get('request');
		if ($path[0] != '/')
			$path = '/'.$path;
		return $request->getScheme().'://'.$request->getHttpHost().$request->getBasePath().$path;
	}
	
	/**
	 * Set a templating slot
	 *
	 * @param string $name Slot name
	 * @param mixed $value Slot value
	 */
	public function setSlot($name, $value) {
		$this->get('templating.engine.php')->get('slots')->set($name, $value);
	}
	
	/**
	 * Get parametred analytics UA
	 * 
	 * @return string
	 */
	public function getAnalyticsUA() {
		return $this->getParameter('analyticsUA');
	}
	
	/**
	 * Get tracking code for analytics if parametered
	 *
	 * @return string
	 */
	public function getTrackingAnalytics() {
		$ret = null;
		$ua = $this->getAnalyticsUA();
		if ($ua) {
			$ret = "<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', '".$ua."', 'routedescommunes.com');
  ga('send', 'pageview');
</script>";
		}
		return $ret;
	}
	
	/**
	 * Urlify a string
	 * 
	 * @param string $text
	 * @return string
	 */
	public function urlify($text) {
		$text = str_replace(
			array('ß' , 'æ',  'Æ',  'Œ', 'œ', '¼',   '½',   '¾',   '‰',   '™', '&'),
			array('ss', 'ae', 'AE', 'OE', 'oe', '1/4', '1/2', '3/4', '0/00', 'TM', '_'),
			$text);
		$from = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøðÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüŠšÝŸÿÑñÐÞþ()[]~¤$&%*@ç§¶!¡†‡?¿;,.#:/\\^¨€¢£¥{}|¦+÷×±<>«»“”„\"‘’' ˜–—…©®¹²³°";
		$to   = 'AAAAAAaaaaaaOOOOOOoooooooEEEEeeeeCcIIIIiiiiUUUUuuuuSsYYyNnDPp           cS        ---     EcPY        __________------CR123-';
		return strtolower(trim(str_replace(
			array(' ', '-----', '----', '---', '--'),
			'-',
			strtr(utf8_decode($text), utf8_decode($from), utf8_decode($to))), '-'));
	}
	
	/**
	 * Get a random string
	 *
	 * @param int $len String length
	 * @param string $ignore Characters to exclude
	 * @return string
	 */
	public function randomStr($len = 20, $ignore = null) {
		$source = 'abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
		if (!is_null($ignore)) {
			$tmp = array();
			for($i=0;$i<strlen($ignore);$i++)<commit_msg>Add getAsseticVersionUrl function<commit_after><?php
namespace NyroDev\UtilityBundle\Services;

class MainService extends AbstractService {
	
	
    /**
     * Generates a URL from the given parameters, allowing extra parameters (like comma)
     *
     * @param  string  $name       The name of the route
     * @param  mixed   $parameters An array of parameters
     * @param  Boolean $absolute   Whether to generate an absolute URL
     * @return string The generated URL
     */
	public function generateUrl($name, $parameters = array(), $absolute = false) {
		if ($name == '#')
			return '#';
		return str_replace('%2C', ',', $this->get('router')->generate($name, $parameters, $absolute));
	}
	
	public function getFullUrl($path) {
		$request = $this->get('request');
		if ($path[0] != '/')
			$path = '/'.$path;
		return $request->getScheme().'://'.$request->getHttpHost().$request->getBasePath().$path;
	}
	
	/**
	 * Set a templating slot
	 *
	 * @param string $name Slot name
	 * @param mixed $value Slot value
	 */
	public function setSlot($name, $value) {
		$this->get('templating.engine.php')->get('slots')->set($name, $value);
	}
	
	/**
	 * Get parametred analytics UA
	 * 
	 * @return string
	 */
	public function getAnalyticsUA() {
		return $this->getParameter('analyticsUA');
	}
	
	/**
	 * Get tracking code for analytics if parametered
	 *
	 * @return string
	 */
	public function getTrackingAnalytics() {
		$ret = null;
		$ua = $this->getAnalyticsUA();
		if ($ua) {
			$ret = "<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', '".$ua."', 'routedescommunes.com');
  ga('send', 'pageview');
</script>";
		}
		return $ret;
	}
	
	/**
	 * Get url with assetic version if configured
	 *
	 * @param string $url
	 * @return string
	 */
	public function getAsseticVersionUrl($url) {
		$tmp = $this->getParameter('assetic_versions');
		
		if ($tmp && is_array($tmp)) {
			$tmpUrl = basename($url);
			$url.= '?'.(isset($tmp[$tmpUrl]) && $tmp[$tmpUrl] ? $tmp[$tmpUrl] : (isset($tmp['global']) ? $tmp['global'] : ''));
		}
		
		return $url;
	}
	
	/**
	 * Urlify a string
	 * 
	 * @param string $text
	 * @return string
	 */
	public function urlify($text) {
		$text = str_replace(
			array('ß' , 'æ',  'Æ',  'Œ', 'œ', '¼',   '½',   '¾',   '‰',   '™', '&'),
			array('ss', 'ae', 'AE', 'OE', 'oe', '1/4', '1/2', '3/4', '0/00', 'TM', '_'),
			$text);
		$from = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøðÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüŠšÝŸÿÑñÐÞþ()[]~¤$&%*@ç§¶!¡†‡?¿;,.#:/\\^¨€¢£¥{}|¦+÷×±<>«»“”„\"‘’' ˜–—…©®¹²³°";
		$to   = 'AAAAAAaaaaaaOOOOOOoooooooEEEEeeeeCcIIIIiiiiUUUUuuuuSsYYyNnDPp           cS        ---     EcPY        __________------CR123-';
		return strtolower(trim(str_replace(
			array(' ', '-----', '----', '---', '--'),
			'-',
			strtr(utf8_decode($text), utf8_decode($from), utf8_decode($to))), '-'));
	}
	
	/**
	 * Get a random string
	 *
	 * @param int $len String length
	 * @param string $ignore Characters to exclude
	 * @return string
	 */
	public function randomStr($len = 20, $ignore = null) {
		$source = 'abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
		if (!is_null($ignore)) {
			$tmp = array();
			for($i=0;$i<strlen($ignore);$i++)
{'fraction_non_alphanumeric': 0.21829136412791597, 'fraction_numerical': 0.010196199598331531, 'mean_word_length': 3.644189383070301, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '778409', 'n_tokens_mistral': 2667, 'n_tokens_neox': 2490, 'n_words': 467}