Skip to content

Commit 993e8a4

Browse files
authored
Merge pull request thephpleague#12 from jonag/add_ignorePassiveAddress_option
Add the ability to configure the ignorePassiveAddress option of the FTP adapter
2 parents 3aa87cb + bb9fde4 commit 993e8a4

6 files changed

Lines changed: 169 additions & 0 deletions

File tree

docs/3-interacting-with-ftp-and-sftp-servers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ flysystem:
2828
passive: true
2929
ssl: true
3030
timeout: 30
31+
ignore_passive_address: ~
3132
```
3233
3334
## SFTP

docs/B-configuration-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ flysystem:
4343
passive: true
4444
ssl: true
4545
timeout: 30
46+
ignore_passive_address: ~
4647

4748
users7.storage:
4849
adapter: 'gcloud'

src/Adapter/Builder/FtpAdapterDefinitionBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ protected function configureOptions(OptionsResolver $resolver)
5757

5858
$resolver->setDefault('timeout', 90);
5959
$resolver->setAllowedTypes('timeout', 'scalar');
60+
61+
$resolver->setDefault('ignore_passive_address', null);
62+
$resolver->setAllowedTypes('ignore_passive_address', ['null', 'bool']);
6063
}
6164

6265
protected function configureDefinition(Definition $definition, array $options)
6366
{
67+
$options['ignorePassiveAddress'] = $options['ignore_passive_address'];
68+
unset($options['ignore_passive_address']);
69+
6470
$definition->setClass(Ftp::class);
6571
$definition->setArgument(0, $options);
6672
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\Adapter\Ftp;
15+
use League\FlysystemBundle\Adapter\Builder\FtpAdapterDefinitionBuilder;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class FtpAdapterDefinitionBuilderTest extends TestCase
19+
{
20+
public function createBuilder()
21+
{
22+
return new FtpAdapterDefinitionBuilder();
23+
}
24+
25+
public function provideValidOptions()
26+
{
27+
yield 'minimal' => [[
28+
'host' => 'ftp.example.com',
29+
'username' => 'username',
30+
'password' => 'password',
31+
]];
32+
33+
yield 'full' => [[
34+
'host' => 'ftp.example.com',
35+
'username' => 'username',
36+
'password' => 'password',
37+
'port' => 21,
38+
'root' => '/path/to/root',
39+
'passive' => true,
40+
'ssl' => true,
41+
'timeout' => 30,
42+
'ignore_passive_address' => true,
43+
]];
44+
}
45+
46+
/**
47+
* @dataProvider provideValidOptions
48+
*/
49+
public function testCreateDefinition($options)
50+
{
51+
$this->assertSame(Ftp::class, $this->createBuilder()->createDefinition($options)->getClass());
52+
}
53+
54+
public function testOptionsBehavior()
55+
{
56+
$definition = $this->createBuilder()->createDefinition([
57+
'host' => 'ftp.example.com',
58+
'username' => 'username',
59+
'password' => 'password',
60+
'port' => 21,
61+
'root' => '/path/to/root',
62+
'passive' => true,
63+
'ssl' => true,
64+
'timeout' => 30,
65+
'ignore_passive_address' => true,
66+
]);
67+
68+
$expected = [
69+
'port' => 21,
70+
'root' => '/path/to/root',
71+
'passive' => true,
72+
'ssl' => true,
73+
'timeout' => 30,
74+
'host' => 'ftp.example.com',
75+
'username' => 'username',
76+
'password' => 'password',
77+
'ignorePassiveAddress' => true,
78+
];
79+
80+
$this->assertSame(Ftp::class, $definition->getClass());
81+
$this->assertSame($expected, $definition->getArgument(0));
82+
}
83+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <galopintitouan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\Sftp\SftpAdapter;
15+
use League\FlysystemBundle\Adapter\Builder\SftpAdapterDefinitionBuilder;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class SftpAdapterDefinitionBuilderTest extends TestCase
19+
{
20+
public function createBuilder()
21+
{
22+
return new SftpAdapterDefinitionBuilder();
23+
}
24+
25+
public function provideValidOptions()
26+
{
27+
yield 'minimal' => [[
28+
'host' => 'ftp.example.com',
29+
'username' => 'username',
30+
'password' => 'password',
31+
]];
32+
33+
yield 'full' => [[
34+
'host' => 'ftp.example.com',
35+
'username' => 'username',
36+
'password' => 'password',
37+
'port' => 22,
38+
'root' => '/path/to/root',
39+
'private_key' => '/path/to/or/contents/of/privatekey',
40+
'timeout' => 30,
41+
]];
42+
}
43+
44+
/**
45+
* @dataProvider provideValidOptions
46+
*/
47+
public function testCreateDefinition($options)
48+
{
49+
$this->assertSame(SftpAdapter::class, $this->createBuilder()->createDefinition($options)->getClass());
50+
}
51+
52+
public function testOptionsBehavior()
53+
{
54+
$definition = $this->createBuilder()->createDefinition([
55+
'host' => 'ftp.example.com',
56+
'username' => 'username',
57+
'password' => 'password',
58+
'port' => 22,
59+
'root' => '/path/to/root',
60+
'private_key' => '/path/to/or/contents/of/privatekey',
61+
'timeout' => 30,
62+
]);
63+
64+
$expected = [
65+
'port' => 22,
66+
'root' => '/path/to/root',
67+
'private_key' => '/path/to/or/contents/of/privatekey',
68+
'timeout' => 30,
69+
'host' => 'ftp.example.com',
70+
'username' => 'username',
71+
'password' => 'password',
72+
];
73+
74+
$this->assertSame(SftpAdapter::class, $definition->getClass());
75+
$this->assertSame($expected, $definition->getArgument(0));
76+
}
77+
}

tests/Adapter/options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fs_ftp:
3535
passive: true
3636
ssl: true
3737
timeout: 30
38+
ignore_passive_address: true
3839

3940
fs_gcloud:
4041
adapter: 'gcloud'

0 commit comments

Comments
 (0)