<?php
namespace ALPCAL\Util;
/**
 * Renames files safely for local storage, replacing URL characters
 * REQUIRES:
 * 	$currentName - name of the incoming, either the nonsafe or safe version
 */

Class CacheFileRenamer
{
	protected $convertToFrom = 
		array(
			'?' => '[q]',
			'&' => '[a]',
			'=' => '[e]',
			'/' => '[fs]',
			':' => '[c]',
			'.' => '[d]',
			);

	public function convertFromUrl($currentName)
	{
		$newName = $currentName;
		foreach ($this->convertToFrom as $k => $v) {
			$newName=str_replace($k, $v, $newName);
		}
		return $newName;
	}

	public function convertToUrl($currentName)
	{
		$newName = $currentName;
		foreach ($this->convertToFrom as $k => $v) {
			$newName=str_replace($v, $k, $newName);
		}
		return $newName;
	}


}
