From 9078e8e667d6bacf22969e800f8d7ece46403d63 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 6 Dec 2011 14:42:01 +0100 Subject: [PATCH 1/3] Add Ftp Adapter --- .../Factory/FtpAdapterFactory.php | 59 +++++++++++++++++++ Resources/config/adapter_factories.xml | 3 + Resources/config/gaufrette.xml | 1 + 3 files changed, 63 insertions(+) create mode 100644 DependencyInjection/Factory/FtpAdapterFactory.php diff --git a/DependencyInjection/Factory/FtpAdapterFactory.php b/DependencyInjection/Factory/FtpAdapterFactory.php new file mode 100644 index 0000000..b6d6201 --- /dev/null +++ b/DependencyInjection/Factory/FtpAdapterFactory.php @@ -0,0 +1,59 @@ +setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.ftp')) + ->addArgument($config['directory']) + ->addArgument($config['host']) + ->addArgument($config['username']) + ->addArgument($config['password']) + ->addArgument($config['port']) + ->addArgument($config['passive']) + ->addArgument($config['create']) + ->addArgument($config['mode']) + ; + } + + /** + * {@inheritDoc} + */ + function getKey() + { + return 'ftp'; + } + + /** + * {@inheritDoc} + */ + function addConfiguration(NodeDefinition $builder) + { + $builder + ->children() + ->scalarNode('directory')->isRequired()->end() + ->scalarNode('host')->isRequired()->end() + ->scalarNode('port')->defaultValue(21)->end() + ->scalarNode('username')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() + ->booleanNode('passive')->defaultFalse()->end() + ->booleanNode('create')->defaultFalse()->end() + ->scalarNode('mode')->defaultValue(FTP_BINARY)->end() + ->end() + ; + } +} \ No newline at end of file diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index 08668a9..1ecddc5 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -29,6 +29,9 @@ + + + diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index ecb16b8..dc75fef 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -26,6 +26,7 @@ + From 2d0d6d830d50103e26ca360f43cf25be5936eb3d Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 6 Dec 2011 17:21:01 +0100 Subject: [PATCH 2/3] Change default value for mode to FTP_ASCII (in order to have the same default value with the constructor of Ftp.php) --- DependencyInjection/Factory/FtpAdapterFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Factory/FtpAdapterFactory.php b/DependencyInjection/Factory/FtpAdapterFactory.php index b6d6201..20d1a3d 100644 --- a/DependencyInjection/Factory/FtpAdapterFactory.php +++ b/DependencyInjection/Factory/FtpAdapterFactory.php @@ -52,8 +52,8 @@ class FtpAdapterFactory implements AdapterFactoryInterface ->scalarNode('password')->defaultNull()->end() ->booleanNode('passive')->defaultFalse()->end() ->booleanNode('create')->defaultFalse()->end() - ->scalarNode('mode')->defaultValue(FTP_BINARY)->end() + ->scalarNode('mode')->defaultValue(FTP_ASCII)->end() ->end() ; } -} \ No newline at end of file +} From 22d8a9f3a94cf3c2bd0691fe4012c3cbd28c48df Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 7 Dec 2011 10:42:40 +0100 Subject: [PATCH 3/3] Add the use of the constant FTP_* in config for FTP transfer mode and add doc for FTP Adapter --- .../Factory/FtpAdapterFactory.php | 7 ++++- README.markdown | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Factory/FtpAdapterFactory.php b/DependencyInjection/Factory/FtpAdapterFactory.php index 20d1a3d..c26ff36 100644 --- a/DependencyInjection/Factory/FtpAdapterFactory.php +++ b/DependencyInjection/Factory/FtpAdapterFactory.php @@ -52,7 +52,12 @@ class FtpAdapterFactory implements AdapterFactoryInterface ->scalarNode('password')->defaultNull()->end() ->booleanNode('passive')->defaultFalse()->end() ->booleanNode('create')->defaultFalse()->end() - ->scalarNode('mode')->defaultValue(FTP_ASCII)->end() + ->scalarNode('mode') + ->defaultValue(FTP_ASCII) + ->beforeNormalization() + ->ifString() + ->then(function($v) { return constant($v); }) + ->end() ->end() ; } diff --git a/README.markdown b/README.markdown index c2ad49e..7b9a3b7 100644 --- a/README.markdown +++ b/README.markdown @@ -284,3 +284,34 @@ knp_gaufrette: ``` [gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette + +## Ftp + +Adapter for FTP. + +### Parameters + + * `directory` The directory of the filesystem *(required)* + * `host` FTP host *(required)* + * `username` FTP username *(default null)* + * `password` FTP password *(default null)* + * `port` FTP port *(default 21)* + * `passive` FTP passive mode *(default false)* + * `create` Whether to create the directory if it does not exist *(default false)* + * `mode` FTP transfer mode *(defaut FTP_ASCII)* + +### Example + +``` yaml +# app/config/config.yml +knp_gaufrette: + adapters: + foo: + ftp: + host: example.com + username: user + password: pass + directory: /example/ftp + create: true + mode: FTP_BINARY +```