Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Validator] Implemented Image constraint
  • Loading branch information
Bernhard Schussek authored and fabpot committed Dec 16, 2010
1 parent 993257a commit a059ec8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -77,7 +77,7 @@ public function isValid($value, Constraint $constraint)

if ($constraint->mimeTypes) {
if (!$value instanceof FileObject) {
throw new ConstraintValidationException();
$value = new FileObject($value);
}

if (!in_array($value->getMimeType(), (array)$constraint->mimeTypes)) {
Expand Down
32 changes: 32 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Image.php
@@ -0,0 +1,32 @@
<?php

namespace Symfony\Component\Validator\Constraints;

/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

class Image extends File
{
public $mimeTypes = array(
'image/png',
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/gif',
);
public $mimeTypesMessage = 'This file is not a valid image';

/**
* @inheritDoc
*/
public function validatedBy()
{
return __NAMESPACE__.'\FileValidator';
}
}

0 comments on commit a059ec8

Please sign in to comment.