This repository was archived by the owner on Jul 22, 2023. It is now read-only.
File tree 4 files changed +94
-0
lines changed
4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ sudo: required
4
4
env :
5
5
global :
6
6
- TEST_S3_LOCATION='//TRAVISACCESSPHPUNIT:wJalrXUtnFEMI%2FSECRET%2FTRAVISPHPUNIT@us-east-1/?endpoint=http%3A%2F%2F127.0.0.1%3A9999&use_path_style_endpoint=1'
7
+ - TEST_FTP_LOCATION='ftp://test:test@localhost'
7
8
8
9
services :
9
10
- docker
@@ -40,6 +41,7 @@ install:
40
41
-e 'MINIO_ACCESS_KEY=TRAVISACCESSPHPUNIT' \
41
42
-e 'MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/TRAVISKEYPHPUNIT' \
42
43
--detach minio/minio server /data"
44
+ - " docker run -d -p 21:21 -p 30000-30009:30000-30009 -e 'PUBLICHOST=localhost' jack12816/ftpd_test"
43
45
44
46
script :
45
47
- composer validate
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MJRider \FlysystemFactory \Adapter ;
4
+
5
+ use League \Flysystem \Filesystem ;
6
+ use League \Flysystem \Adapter \Ftp as Adapter ;
7
+
8
+ /**
9
+ * Static factory class for creating an ftp connection
10
+ */
11
+ class Ftp implements AdapterFactoryInterface
12
+ {
13
+ /**
14
+ * Builds the arguments for the FTP adapter
15
+ *
16
+ * @param [string] $url
17
+ * @return void
18
+ */
19
+ protected static function buildArgs ($ url )
20
+ {
21
+ $ args = [
22
+ 'host ' => $ url ->host ,
23
+ 'username ' => urldecode ($ url ->user ),
24
+ 'password ' => urldecode ($ url ->pass ),
25
+ 'port ' => $ url ->port ,
26
+ 'root ' => $ url ->path ,
27
+ ];
28
+
29
+ if (isset ($ url ->query ->passive )) {
30
+ $ args [ 'passive ' ] = (bool )$ url ->query ->passive ;
31
+ }
32
+
33
+ if (isset ($ url ->query ->ssl )) {
34
+ $ args [ 'ssl ' ] = (bool )$ url ->query ->ssl ;
35
+ }
36
+
37
+ if (isset ($ url ->query ->timeout )) {
38
+ $ args [ 'timeout ' ] = (int )$ url ->query ->timeout ;
39
+ }
40
+
41
+ return $ args ;
42
+ }
43
+
44
+ /**
45
+ * Creates the adapter for FTP
46
+ *
47
+ * @param [string] $url
48
+ * @return void
49
+ */
50
+ public static function create ($ url )
51
+ {
52
+ $ args = static ::buildArgs ($ url );
53
+
54
+ $ adapter = new Adapter ($ args );
55
+
56
+ return $ adapter ;
57
+ }
58
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ function create($endpoint)
30
30
case 'b2 ' :
31
31
$ adapter = Adapter \B2 ::create ($ url );
32
32
break ;
33
+ case 'ftp ' :
34
+ $ adapter = Adapter \Ftp::create ($ url );
35
+ break ;
33
36
case 'file ' :
34
37
case 'local ' :
35
38
$ adapter = Adapter \Local::create ($ url );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MJRider \FlysystemFactory \Adapter ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+
7
+ /**
8
+ * @requires PHP 5.4
9
+ */
10
+ class FtpTest extends TestCase
11
+ {
12
+ protected $ root = '' ;
13
+
14
+ public function setup ()
15
+ {
16
+ $ this ->root = getenv ('TEST_FTP_LOCATION ' );
17
+ if ($ this ->root === false ) {
18
+ $ this ->markTestSkipped ('no ftp endpoint available, test skipped ' );
19
+ }
20
+ if (defined ('HHVM_VERSION ' )) {
21
+ $ this ->markTestSkipped ('HHVM ftp not supported ' );
22
+ }
23
+ }
24
+
25
+ public function testFtp ()
26
+ {
27
+ $ filesystem = \MJRider \FlysystemFactory \create ($ this ->root );
28
+ $ this ->assertInstanceOf ('\League\Flysystem\Filesystem ' , $ filesystem );
29
+ $ this ->assertInstanceOf ('\League\Flysystem\Adapter\Ftp ' , $ filesystem ->getAdapter ());
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments