Merge pull request #9 from vincent42/master

Add Ftp Adapter
This commit is contained in:
Antoine Hérault 2011-12-07 04:27:27 -08:00
commit 2d7666a413
4 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,64 @@
<?php
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
/**
* Ftp Adapter Factory
*/
class FtpAdapterFactory implements AdapterFactoryInterface
{
/**
* {@inheritDoc}
*/
function create(ContainerBuilder $container, $id, array $config)
{
$container
->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_ASCII)
->beforeNormalization()
->ifString()
->then(function($v) { return constant($v); })
->end()
->end()
;
}
}

View File

@ -284,3 +284,34 @@ knp_gaufrette:
``` ```
[gaufrette-homepage]: https://github.com/KnpLabs/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
```

View File

@ -29,6 +29,9 @@
<service id="knp_gaufrette.adapter.factory.mogilefs" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\MogileFSAdapterFactory"> <service id="knp_gaufrette.adapter.factory.mogilefs" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\MogileFSAdapterFactory">
<tag name="gaufrette.adapter.factory" /> <tag name="gaufrette.adapter.factory" />
</service> </service>
<service id="knp_gaufrette.adapter.factory.ftp" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\FtpAdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>
</services> </services>

View File

@ -26,6 +26,7 @@
<argument /><!-- domain --> <argument /><!-- domain -->
<argument /><!-- hosts --> <argument /><!-- hosts -->
</service> </service>
<service id="knp_gaufrette.adapter.ftp" class="Gaufrette\Adapter\Ftp" abstract="true" public="false" />
<service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap"> <service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap">
<argument /> <!-- map of filesystems --> <argument /> <!-- map of filesystems -->
</service> </service>