Example #1
0
 /**
  * Input construct.
  *
  * @param array $name
  * @param mixed $value
  * @param array|null $inputConfig
  * @throws InvalidArgumentException
  */
 public function __construct($name, $value, $inputConfig)
 {
     if (!is_array($value)) {
         if (is_object($value) && in_array("__toString", get_class_methods($value))) {
             $value = strval($value->__toString());
         } else {
             $value = strval($value);
         }
         $value = trim($value);
         if ($value !== '') {
             $value = str_replace('"', '"', $value);
             $value = json_decode($value, true);
             // strict mode
             if (json_last_error() != JSON_ERROR_NONE || !is_array($value)) {
                 throw new InvalidArgumentException('Invalid string to convert to array');
             }
         }
     }
     parent::__construct($name, $value, $inputConfig);
 }
Example #2
0
 /**
  * Get valid value for the input.
  *
  * @return mixed|null
  */
 public function getValidValue()
 {
     $valid = parent::getValidValue();
     error_log('FileInput [getValidValue] ' . var_export($valid, true));
     if ($valid instanceof UploadedFileInterface) {
         $obj = new stdClass();
         //$obj->uploadedFile = $valid;
         $obj->originalName = $valid->getClientFilename();
         $obj->type = $valid->getClientMediaType();
         $obj->size = $valid->getSize();
         $obj->error = $valid->getError();
         //$obj->folder = trim($this->getFolder(), DS);
         $randomName = $this->randomName();
         $randomFullName = $randomName . '.' . $this->getExtension($obj->originalName);
         $newPath = rtrim(FILE_PATH, DS) . DS . ($this->getFolder() ? trim($this->getFolder(), DS) . DS : '') . $randomFullName;
         $valid->moveTo($newPath);
         $obj->name = $randomFullName;
         $obj->fullname = $newPath;
         return $obj;
     }
     return null;
 }
Example #3
0
 /**
  * Get the default value of the input
  *
  * @return mixed
  */
 public function getDefaultValue()
 {
     return parent::getDefaultValue();
 }