44
55use Illuminate \Contracts \Filesystem \Filesystem as FilesystemContract ;
66use Illuminate \Support \Collection ;
7+ use Illuminate \Filesystem \FilesystemAdapter ;
78use League \Flysystem \Adapter \Local ;
9+ use League \Flysystem \Local \LocalFilesystemAdapter ;
810use League \Flysystem \FilesystemInterface ;
911use Pion \Laravel \ChunkUpload \ChunkFile ;
1012use Pion \Laravel \ChunkUpload \Config \AbstractConfig ;
@@ -28,52 +30,61 @@ public static function storage()
2830 * @var AbstractConfig
2931 */
3032 protected $ config ;
31-
3233 /**
3334 * The disk that holds the chunk files.
3435 *
35- * @var FilesystemAdapter
36+ * @var FilesystemContract| FilesystemAdapter
3637 */
3738 protected $ disk ;
38-
3939 /**
40- * @var Local
40+ * @var Local|LocalFilesystemAdapter
4141 */
4242 protected $ diskAdapter ;
43+ protected $ isLocalDisk ;
4344
4445 /**
45- * Is provided disk a local drive.
46- *
47- * @var bool
46+ * @var
4847 */
49- protected $ isLocalDisk ;
48+ protected $ usingDeprecatedLaravel ;
5049
5150 /**
52- * ChunkStorage constructor.
53- *
54- * @param FilesystemContract $disk the desired disk for chunk storage
55- * @param AbstractConfig $config
51+ * @param FilesystemAdapter|FilesystemContract $disk the desired disk for chunk storage
52+ * @param AbstractConfig $config
5653 */
57- public function __construct (FilesystemContract $ disk , $ config )
54+ public function __construct ($ disk , $ config )
5855 {
5956 // save the config
6057 $ this ->config = $ config ;
61-
62- // cache the storage path
58+ $ this ->usingDeprecatedLaravel = class_exists (LocalFilesystemAdapter::class) === false ;
6359 $ this ->disk = $ disk ;
6460
65- $ driver = $ this ->driver ();
61+ if ( $ this ->usingDeprecatedLaravel === false ) {
6662
67- // try to get the adapter
68- if (!method_exists ($ driver , 'getAdapter ' )) {
69- throw new RuntimeException ('FileSystem driver must have an adapter implemented ' );
70- }
63+ // try to get the adapter
64+ if (!method_exists ($ this ->disk , 'getAdapter ' )) {
65+ throw new RuntimeException ('FileSystem driver must have an adapter implemented ' );
66+ }
67+
68+ // get the disk adapter
69+ $ this ->diskAdapter = $ this ->disk ->getAdapter ();
7170
72- // get the disk adapter
73- $ this ->diskAdapter = $ driver ->getAdapter ();
71+ // check if its local adapter
72+ $ this ->isLocalDisk = $ this ->diskAdapter instanceof LocalFilesystemAdapter;
73+ } else {
74+ $ driver = $ this ->driver ();
75+
76+ // try to get the adapter
77+ if (!method_exists ($ driver , 'getAdapter ' )) {
78+ throw new RuntimeException ('FileSystem driver must have an adapter implemented ' );
79+ }
80+
81+ // get the disk adapter
82+ $ this ->diskAdapter = $ driver ->getAdapter ();
83+
84+ // check if its local adapter
85+ $ this ->isLocalDisk = $ this ->diskAdapter instanceof Local;
86+ }
7487
75- // check if its local adapter
76- $ this ->isLocalDisk = $ this ->diskAdapter instanceof Local;
7788 }
7889
7990 /**
@@ -85,10 +96,14 @@ public function __construct(FilesystemContract $disk, $config)
8596 */
8697 public function getDiskPathPrefix ()
8798 {
88- if ($ this ->isLocalDisk ) {
99+ if ($ this ->usingDeprecatedLaravel === true && $ this -> isLocalDisk ) {
89100 return $ this ->diskAdapter ->getPathPrefix ();
90101 }
91102
103+ if ($ this ->isLocalDisk ) {
104+ return $ this ->disk ->path ('' );
105+ }
106+
92107 throw new RuntimeException ('The full path is not supported on current disk - local adapter supported only ' );
93108 }
94109
@@ -99,7 +114,7 @@ public function getDiskPathPrefix()
99114 */
100115 public function directory ()
101116 {
102- return $ this ->config ->chunksStorageDirectory (). '/ ' ;
117+ return $ this ->config ->chunksStorageDirectory () . '/ ' ;
103118 }
104119
105120 /**
@@ -119,7 +134,7 @@ public function files($rejectClosure = null)
119134
120135 return $ filesCollection ->reject (function ($ file ) use ($ rejectClosure ) {
121136 // ensure the file ends with allowed extension
122- $ shouldReject = !preg_match ('/. ' . self ::CHUNK_EXTENSION . '$/ ' , $ file );
137+ $ shouldReject = !preg_match ('/. ' . self ::CHUNK_EXTENSION . '$/ ' , $ file );
123138 if ($ shouldReject ) {
124139 return true ;
125140 }
@@ -182,7 +197,7 @@ public function disk()
182197 /**
183198 * Returns the driver.
184199 *
185- * @return FilesystemInterface
200+ * @return FilesystemOperator| FilesystemInterface
186201 */
187202 public function driver ()
188203 {
0 commit comments