public function writeJsVariable(array $variables, $lineBeginWith = "var")
	{
		//common checks
		if(!file_exists($this->file)){
			throw new tao_install_utils_Exception("Unable to write variables: $this->file don't exists!");
		}
		if(!is_readable($this->file) || !is_writable($this->file)){
			throw new tao_install_utils_Exception("Unable to write variables: $this->file must have read and write permissions!");
		}
		
		$lines 	= file($this->file);
		if($lines !== false){
			$data = file_get_contents($this->file);
			$changes = 0;
			foreach($lines as $line){
				foreach($variables as $key => $value){
					if(is_string($value)){
						$value = "'$value'";
					}
					else if(is_bool($value)){
						($value === true) ? $value = 'true' : $value = 'false';
					}
					
					if(preg_match("/^\s?$lineBeginWith\s?$key\s?=\s?/i", trim($line))){
						$data = str_replace(trim($line), "$lineBeginWith $key = $value;", $data);
						$changes++;
					}
				}
			}
			if($changes > 0){
				file_put_contents($this->file, $data);
			}
		}
	}
public function writeJsVariable(array $variables, $lineBeginWith = "var")
	{
		//common checks
		if(!file_exists($this->file)){
			throw new tao_install_utils_Exception("Unable to write variables: $this->file don't exists!");
		}
		if(!is_readable($this->file) || !is_writable($this->file)){
			throw new tao_install_utils_Exception("Unable to write variables: $this->file must have read and write permissions!");
		}
		
		$lines 	= file($this->file);
		if($lines !== false){
			$data = file_get_contents($this->file);
			$changes = 0;
			foreach($lines as $line){
				foreach($variables as $key => $value){
					if(is_string($value)){
						$value = "'$value'";
					}
					else if(is_bool($value)){
						($value === true) ? $value = 'true' : $value = 'false';
					}
					
					if(preg_match("/^\s?$lineBeginWith\s?$key\s?=\s?/i", trim($line))){
						$data = str_replace(trim($line), "$lineBeginWith $key = $value;", $data);
						$changes++;
					}
				}
			}
			if($changes > 0){
				file_put_contents($this->file, $data);
			}
		}
	}
public function writeJsVariable ( array $ variables , $ lineBeginWith = "var" ) { //common checks if ( ! file_exists ( $ this -> file ) ) { throw new tao_install_utils_Exception ( "Unable to write variables: $this->file don't exists!" ) ; } if ( ! is_readable ( $ this -> file ) || ! is_writable ( $ this -> file ) ) { throw new tao_install_utils_Exception ( "Unable to write variables: $this->file must have read and write permissions!" ) ; } $ lines = file ( $ this -> file ) ; if ( $ lines !== false ) { $ data = file_get_contents ( $ this -> file ) ; $ changes = 0 ; foreach ( $ lines as $ line ) { foreach ( $ variables as $ key => $ value ) { if ( is_string ( $ value ) ) { $ value = "'$value'" ; } else if ( is_bool ( $ value ) ) { ( $ value === true ) ? $ value = 'true' : $ value = 'false' ; } if ( preg_match ( "/^\s?$lineBeginWith\s?$key\s?=\s?/i" , trim ( $ line ) ) ) { $ data = str_replace ( trim ( $ line ) , "$lineBeginWith $key = $value;" , $ data ) ; $ changes ++ ; } } } if ( $ changes > 0 ) { file_put_contents ( $ this -> file , $ data ) ; } } }
Write the constants into a Javascript config file
@param array $variables the list of variables to write (the key is the name of the var)
@throws tao_install_utils_Exception
Write the constants into a Javascript config file