From 04b491621e51eadf837133e6c0f3bacdc940c8f2 Mon Sep 17 00:00:00 2001 From: wuyanwen Date: Sat, 25 Jan 2020 22:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchUpload.php | 258 ++++++++++++++++++--------------- 1 file changed, 141 insertions(+), 117 deletions(-) diff --git a/extend/catcher/CatchUpload.php b/extend/catcher/CatchUpload.php index 864cf4a..01b3d4d 100644 --- a/extend/catcher/CatchUpload.php +++ b/extend/catcher/CatchUpload.php @@ -1,117 +1,141 @@ -getDriver())->putFile($this->getPath(), $file); - } - - /** - * get upload driver - * - * @author JaguarJack - * @email njphper@gmail.com - * @time 2020/1/25 - * @return string - */ - protected function getDriver() - { - return $this->driver; - } - - /** - * set driver - * - * @author JaguarJack - * @email njphper@gmail.com - * @time 2020/1/25 - * @param $driver - * @throws \Exception - * @return $this - */ - public function setDriver($driver) - { - if (!in_array($driver, [self::OSS, self::QCLOUD, self::QIQNIU, self::LOCAL])) { - throw new \Exception(sprintf('Upload Driver [%s] Not Supported', $driver)); - } - - $this->driver = $driver; - - return $this; - } - - /** - * - * @author JaguarJack - * @email njphper@gmail.com - * @time 2020/1/25 - * @return string - */ - protected function getPath() - { - return $this->path; - } - - /** - * - * @author JaguarJack - * @email njphper@gmail.com - * @time 2020/1/25 - * @param string $path - * @return $this - */ - public function setPath(string $path) - { - $this->path = $path; - - return $this; - } -} \ No newline at end of file +getDriver())->putFile($this->getPath(), $file); + + if ($path) { + Attachments::create(array_merge(['path' => $path], $this->data($file))); + } + + return ['path' => Utils::getCloudDomain($this->getDriver()) . $path]; + } + + /** + * get upload driver + * + * @author JaguarJack + * @email njphper@gmail.com + * @time 2020/1/25 + * @return string + */ + protected function getDriver(): string + { + return $this->driver; + } + + /** + * set driver + * + * @author JaguarJack + * @email njphper@gmail.com + * @time 2020/1/25 + * @param $driver + * @throws \Exception + * @return $this + */ + public function setDriver($driver): self + { + if (!in_array($driver, [self::OSS, self::QCLOUD, self::QIQNIU, self::LOCAL])) { + throw new \Exception(sprintf('Upload Driver [%s] Not Supported', $driver)); + } + + $this->driver = $driver; + + return $this; + } + + /** + * + * @author JaguarJack + * @email njphper@gmail.com + * @time 2020/1/25 + * @return string + */ + protected function getPath() + { + return $this->path; + } + + /** + * + * @author JaguarJack + * @email njphper@gmail.com + * @time 2020/1/25 + * @param string $path + * @return $this + */ + public function setPath(string $path) + { + $this->path = $path; + + return $this; + } + + /** + * + * @time 2020年01月25日 + * @param UploadedFile $file + * @return array + */ + protected function data(UploadedFile $file) + { + return [ + 'file_size' => $file->getSize(), + 'mime_type' => $file->getMime(), + 'file_ext' => $file->getExtension(), + 'filename' => $file->getOriginalName(), + 'driver' => $this->getDriver(), + ]; + } +}