size; } /** * @return string */ public function getType() { return $this->type; } /** * @return string */ public function getError() { return $this->error; } public function getMime() { return $this->getType(); } /** * @return string */ public function getTmpName() { return $this->tmpName; } public function getExtension() { return pathinfo($this->getName(), PATHINFO_EXTENSION); } public function move($destination) { return move_uploaded_file($this->tmpName, $destination); } public function getContents() { return file_get_contents($this->tmpName); } /** * Set file temp. name * @param string $name * @return static $this */ public function setTmpName($name) { $this->tmpName = $name; return $this; } /** * Set file size * @param int $size * @return static $this */ public function setSize($size) { $this->size = $size; return $this; } /** * Set type * @param string $type * @return static $this */ public function setType($type) { $this->type = $type; return $this; } /** * Set error * @param int $error * @return static $this */ public function setError($error) { $this->error = (int)$error; return $this; } public function getValue() { return $this->getTmpName(); } public function hasError() { return ($this->getError() !== 0); } /** * Create from array * @param array $values * @return static */ public static function createFromArray(array $values) { if(!isset($values['index'])) { throw new \InvalidArgumentException('Index key is required'); } $input = new static($values['index']); $input->setError((isset($values['error']) ? $values['error'] : null)); $input->setName((isset($values['name']) ? $values['name'] : null)); $input->setSize((isset($values['size']) ? $values['size'] : null)); $input->setType((isset($values['type']) ? $values['type'] : null)); $input->setTmpName((isset($values['tmp_name']) ? $values['tmp_name'] : null)); return $input; } public function toArray() { return [ 'tmp_name' => $this->tmpName, 'type' => $this->type, 'size' => $this->size, 'name' => $this->name, 'error' => $this->error, ]; } }