File tree Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace FileUpload \Exceptions ;
5+
6+ use Throwable ;
7+
8+ class FileContentException extends \Exception
9+ {
10+ /**
11+ * @param string $message Message
12+ * @param int $code Exception code
13+ * @param \Throwable|null $previous The previous throwable used for the exception chaining.
14+ */
15+ public function __construct ($ message = 'Cannot load content of file ' , $ code = 1 , ?Throwable $ previous = null )
16+ {
17+ parent ::__construct ($ message , $ code , $ previous );
18+ }
19+ }
Original file line number Diff line number Diff line change 55
66class UploadedFile implements StoredFileInterface
77{
8+ /**
9+ * @var string $fileName
10+ */
811 protected $ fileName ;
912
13+ /**
14+ * @var string $path
15+ */
1016 protected $ path ;
1117
18+ /**
19+ * @var string $storageType
20+ */
1221 protected $ storageType ;
1322
23+ /**
24+ * @var string $fileType
25+ */
1426 protected $ fileType ;
1527
28+ /**
29+ * @var string $fileContent
30+ */
1631 protected $ fileContent ;
1732
1833 /**
19- * @return mixed
34+ * @return string
2035 */
2136 public function getFileName (): string
2237 {
2338 return $ this ->fileName ;
2439 }
2540
2641 /**
27- * @param mixed $fileName File name
42+ * @param string $fileName File name
2843 * @return void
2944 */
3045 public function setFileName ($ fileName ): void
3146 {
3247 $ this ->fileName = $ fileName ;
3348
49+ /** @var string[] $pathInfo */
3450 $ pathInfo = pathinfo ($ fileName );
3551 $ this ->fileType = $ pathInfo ['extension ' ];
3652 }
3753
3854 /**
39- * @return mixed
55+ * @return string
4056 */
4157 public function getPath (): string
4258 {
4359 return $ this ->path ;
4460 }
4561
4662 /**
47- * @param mixed $path Path to file without filename
63+ * @param string $path Path to file without filename
4864 * @return void
4965 */
50- public function setPath ($ path ): void
66+ public function setPath (string $ path ): void
5167 {
5268 $ this ->path = $ path ;
5369 }
@@ -70,7 +86,7 @@ public function setStorageType(string $storageType): void
7086 }
7187
7288 /**
73- * @return mixed
89+ * @return string
7490 */
7591 public function getFileType (): string
7692 {
Original file line number Diff line number Diff line change 33
44namespace FileUpload \Storage ;
55
6+ use FileUpload \Exceptions \FileContentException ;
67use FileUpload \File \StoredFileInterface ;
78use FileUpload \File \UploadedFile ;
89use Psr \Http \Message \UploadedFileInterface ;
@@ -45,11 +46,16 @@ public function put(UploadedFileInterface $fileObject): StoredFileInterface
4546 *
4647 * @param string $fileName Filename without slashes
4748 * @return \FileUpload\File\StoredFileInterface
49+ * @throws \FileUpload\Exceptions\FileContentException
4850 */
4951 public function pull (string $ fileName ): StoredFileInterface
5052 {
5153 $ fileContent = file_get_contents ($ this ->configuration ->getConfig ('storagePath ' ) . $ fileName );
5254
55+ if ($ fileContent == false ) {
56+ throw new FileContentException ();
57+ }
58+
5359 $ uploadedFile = new UploadedFile ();
5460 $ uploadedFile ->setFileName ($ fileName );
5561 $ uploadedFile ->setPath ($ this ->configuration ->getConfig ('storagePath ' ));
You can’t perform that action at this time.
0 commit comments