<?php
namespace Engine\Mvc\Response;

class FileView extends FileDownload
{
	/**
	 * Stores the type of file (eg: pdf, html etc)
	 * @var String
	 */
	private $filetype = NULL;

	/**
	 * Set the file name
	 * @param string $filename
	 */
	public function setFiletype($filetype)
	{
		$this->filetype = $filetype;
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Mvc\Response\GeneralAbstract::getHeadersFinal()
	 */
	public function getHeadersFinal()
	{
		$headers = parent::getHeadersFinal();

		// get file type
		$filetype = $this->filetype;
		if (!$filetype) {
			$filetype = \Engine\File::getExtension($this->filename);
		}

		$headers->append('Content-Disposition', sprintf('inline; filename="%s";', $this->filename));

		switch (strtolower($filetype)) {
			case 'pdf':
				$headers->append("Content-Type", "application/pdf");
			break;

			case 'html':
				$headers->append("Content-Type", "text/html");
			break;

			case 'mhtml':
				$headers->append("Content-Type", "message/rfc822");
			break;

			case 'xml':
				$headers->append("Content-Type", "text/xml");
			break;

			// images
			case 'gif':
				$headers->append("Content-Type", "image/gif");
			break;

			case 'jpg':
			case 'jpeg':
				$headers->append("Content-Type", "image/jpeg");
			break;

			case 'png':
				$headers->append("Content-Type", "image/png");
			break;

			case 'webp':
				$headers->append("Content-Type", "image/webp");
			break;

			case 'bmp':
				$headers->append("Content-Type", "image/bmp");
			break;

			case 'svg':
				$headers->append("Content-Type", "image/svg+xml");
			break;

			default:
				$headers->append("Content-Type", "application/octet-stream");
		}

		return $headers;
	}

	/**
	 * Generate the list of headers
	 */
	protected function generateDownloadHeaders()
	{
	}
}
