Awesome features (you'll see)

This commit is contained in:
Maxime Renou 2019-02-21 12:28:50 +01:00
parent 1efd84bdb5
commit 1bfde01f42
2 changed files with 34 additions and 1 deletions

View File

@ -2,6 +2,8 @@
namespace Bluesquare\ValidatorBundle; namespace Bluesquare\ValidatorBundle;
use Bluesquare\StorageBundle\Exceptions\MimeTypeException;
use Bluesquare\StorageBundle\Storage;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -206,6 +208,36 @@ class Validator
return true; return true;
} }
public function injectFile()
{
$args = func_get_args();
if (count($args) === 0) return false;
if (is_object($args[0])) $entity = array_shift($args);
else $entity = $this->entity;
if (is_null($entity) || count($args) != 2) return false;
$attribute = $args[0];
$storage = $args[1];
// handle
if (!$this->hasFile($attribute))
{
$this->error($attribute, 'required');
return false;
}
if ($storage instanceof Storage)
{
try {
return $storage->store($entity, $attribute, $this->getFile($attribute));
}
catch(MimeTypeException $exception) {
$this->error($attribute, 'file_mime_type');
}
}
return false;
}
// //
public function post() public function post()

View File

@ -12,7 +12,8 @@
"type": "symfony-bundle", "type": "symfony-bundle",
"require": { "require": {
"php": ">=7.1", "php": ">=7.1",
"symfony/translation": "^4.2" "symfony/translation": "^4.2",
"bluesquare-packages/symfony-storage": "dev-master"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {