<?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 ($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;

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

		return $headers;
	}

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