Awesome features (you'll see)
This commit is contained in:
parent
1efd84bdb5
commit
1bfde01f42
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Bluesquare\ValidatorBundle;
|
||||
|
||||
use Bluesquare\StorageBundle\Exceptions\MimeTypeException;
|
||||
use Bluesquare\StorageBundle\Storage;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
|
@ -206,6 +208,36 @@ class Validator
|
|||
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()
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
"type": "symfony-bundle",
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"symfony/translation": "^4.2"
|
||||
"symfony/translation": "^4.2",
|
||||
"bluesquare-packages/symfony-storage": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
Loading…
Reference in New Issue