laravel-6 support
This commit is contained in:
@@ -27,12 +27,12 @@ class FileFormField extends FormField
|
||||
*/
|
||||
public function setErrorCode($error)
|
||||
{
|
||||
$codes = array(UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION);
|
||||
if (!in_array($error, $codes)) {
|
||||
throw new \InvalidArgumentException(sprintf('The error code %s is not valid.', $error));
|
||||
$codes = [\UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_EXTENSION];
|
||||
if (!\in_array($error, $codes)) {
|
||||
throw new \InvalidArgumentException(sprintf('The error code "%s" is not valid.', $error));
|
||||
}
|
||||
|
||||
$this->value = array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0);
|
||||
$this->value = ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,19 +48,19 @@ class FileFormField extends FormField
|
||||
/**
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* @param string $value The value of the field
|
||||
* @param string|null $value The value of the field
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if (null !== $value && is_readable($value)) {
|
||||
$error = UPLOAD_ERR_OK;
|
||||
$error = \UPLOAD_ERR_OK;
|
||||
$size = filesize($value);
|
||||
$info = pathinfo($value);
|
||||
$name = $info['basename'];
|
||||
|
||||
// copy to a tmp location
|
||||
$tmp = sys_get_temp_dir().'/'.sha1(uniqid(mt_rand(), true));
|
||||
if (array_key_exists('extension', $info)) {
|
||||
$tmp = sys_get_temp_dir().'/'.strtr(substr(base64_encode(hash('sha256', uniqid(mt_rand(), true), true)), 0, 7), '/', '_');
|
||||
if (\array_key_exists('extension', $info)) {
|
||||
$tmp .= '.'.$info['extension'];
|
||||
}
|
||||
if (is_file($tmp)) {
|
||||
@@ -69,13 +69,13 @@ class FileFormField extends FormField
|
||||
copy($value, $tmp);
|
||||
$value = $tmp;
|
||||
} else {
|
||||
$error = UPLOAD_ERR_NO_FILE;
|
||||
$error = \UPLOAD_ERR_NO_FILE;
|
||||
$size = 0;
|
||||
$name = '';
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$this->value = array('name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size);
|
||||
$this->value = ['name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ class FileFormField extends FormField
|
||||
}
|
||||
|
||||
if ('file' !== strtolower($this->node->getAttribute('type'))) {
|
||||
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type')));
|
||||
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is "%s").', $this->node->getAttribute('type')));
|
||||
}
|
||||
|
||||
$this->setValue(null);
|
||||
|
Reference in New Issue
Block a user