This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/Constraints/File.php
Fabien Potencier 842cba1d0c Merge branch '2.5'
* 2.5:
  Remove aligned '=>' and '='
  Break infinite loop while resolving aliases
  [Security][listener] change priority of switchuser
  Improved the phpdoc for security token classes
  bumped Symfony version to 2.5.7
  updated VERSION for 2.5.6
  updated CHANGELOG for 2.5.6
  bumped Symfony version to 2.3.22
  updated VERSION for 2.3.21
  update CONTRIBUTORS for 2.3.21
  updated CHANGELOG for 2.3.21

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
	src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php
	src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
	src/Symfony/Component/Debug/ErrorHandler.php
	src/Symfony/Component/Debug/ExceptionHandler.php
	src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
	src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
	src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
	src/Symfony/Component/Form/Extension/Core/Type/DateType.php
	src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
	src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
	src/Symfony/Component/HttpFoundation/Request.php
	src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php
	src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
	src/Symfony/Component/HttpKernel/Kernel.php
	src/Symfony/Component/Security/Core/SecurityContextInterface.php
	src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php
	src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php
	src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php
	src/Symfony/Component/Serializer/Serializer.php
	src/Symfony/Component/Validator/Constraints/File.php
2014-10-26 08:46:28 +01:00

87 lines
3.6 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @api
*/
class File extends Constraint
{
// Check the Image constraint for clashes if adding new constants here
const NOT_FOUND_ERROR = 1;
const NOT_READABLE_ERROR = 2;
const EMPTY_ERROR = 3;
const TOO_LARGE_ERROR = 4;
const INVALID_MIME_TYPE_ERROR = 5;
protected static $errorNames = array(
self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR',
self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR',
self::EMPTY_ERROR => 'EMPTY_ERROR',
self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR',
);
public $maxSize;
public $binaryFormat;
public $mimeTypes = array();
public $notFoundMessage = 'The file could not be found.';
public $notReadableMessage = 'The file is not readable.';
public $maxSizeMessage = 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.';
public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
public $disallowEmptyMessage = 'An empty file is not allowed.';
public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.';
public $uploadFormSizeErrorMessage = 'The file is too large.';
public $uploadPartialErrorMessage = 'The file was only partially uploaded.';
public $uploadNoFileErrorMessage = 'No file was uploaded.';
public $uploadNoTmpDirErrorMessage = 'No temporary folder was configured in php.ini.';
public $uploadCantWriteErrorMessage = 'Cannot write temporary file to disk.';
public $uploadExtensionErrorMessage = 'A PHP extension caused the upload to fail.';
public $uploadErrorMessage = 'The file could not be uploaded.';
public function __construct($options = null)
{
parent::__construct($options);
if ($this->maxSize) {
if (ctype_digit((string) $this->maxSize)) {
$this->maxSize = (int) $this->maxSize;
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++k$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize * 1000;
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++M$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize * 1000000;
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^\d++Ki$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize << 10;
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
} elseif (preg_match('/^\d++Mi$/i', $this->maxSize)) {
$this->maxSize = $this->maxSize << 20;
$this->binaryFormat = null === $this->binaryFormat ? true : $this->binaryFormat;
} else {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
}
}
}
}