add type to WrongFiletypeException

This commit is contained in:
coderkun 2014-04-04 14:00:01 +02:00
commit 992ce8a37c
3 changed files with 29 additions and 5 deletions

View file

@ -30,7 +30,14 @@
* *
* @var string * @var string
*/ */
const MESSAGE = 'File has wrong type'; const MESSAGE = 'File has wrong type “%s”';
/**
* Type of file
*
* @var string
*/
private $type;
@ -38,12 +45,29 @@
/** /**
* Construct a new exception. * Construct a new exception.
*/ */
function __construct($message=self::MESSAGE, $code=self::CODE) function __construct($type, $message=self::MESSAGE, $code=self::CODE)
{ {
parent::__construct( parent::__construct(
$message, $message,
$code $code,
$type
); );
// Store values
$this->type = $type;
}
/**
* Get type of file.
*
* @return Type of file
*/
public function getType()
{
return $this->type;
} }
} }

View file

@ -67,7 +67,7 @@
} }
if(is_null($answerMimetype)) { if(is_null($answerMimetype)) {
throw new \hhu\z\exceptions\SubmissionNotValidException( throw new \hhu\z\exceptions\SubmissionNotValidException(
new \hhu\z\exceptions\WrongFiletypeException() new \hhu\z\exceptions\WrongFiletypeException($answer['type'])
); );
} }

View file

@ -1,7 +1,7 @@
<?php if(!is_null($exception)) : ?> <?php if(!is_null($exception)) : ?>
<p class="error"> <p class="error">
<?php if($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?> <?php if($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?>
<?=_('File has wrong type')?> <?=sprintf(_('File has wrong type “%s”'), $exception->getNestedException()->getType())?>
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?> <?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?>
<?=_('File exceeds size maximum')?> <?=_('File exceeds size maximum')?>
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\FileUploadException) : ?> <?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\FileUploadException) : ?>