Skip to content

Commit

Permalink
Merge pull request #67 from radutopala/master
Browse files Browse the repository at this point in the history
Dropbox Adapter Factory added
  • Loading branch information
l3l0 committed Nov 4, 2013
2 parents c01f131 + 209928f commit 9e70925
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
45 changes: 45 additions & 0 deletions DependencyInjection/Factory/DropboxAdapterFactory.php
@@ -0,0 +1,45 @@
<?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;

/**
* Dropbox Adapter Factory
*/
class DropboxAdapterFactory implements AdapterFactoryInterface
{
/**
* {@inheritDoc}
*/
function create(ContainerBuilder $container, $id, array $config)
{
$container
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.dropbox'))
->addArgument(new Reference($config['api_id']))
;
}

/**
* {@inheritDoc}
*/
function getKey()
{
return 'dropbox';
}

/**
* {@inheritDoc}
*/
function addConfiguration(NodeDefinition $builder)
{
$builder
->children()
->scalarNode('api_id')->cannotBeEmpty()->end()
->end()
;
}
}
42 changes: 42 additions & 0 deletions README.markdown
Expand Up @@ -809,4 +809,46 @@ knp_gaufrette:
checksum: checksum
```

## Dropbox (dropbox)

Adapter for Dropbox.

### Parameters

* `api_id` The id of the service that provides Dropbox API access.

### Example

> In order to get a Dropbox token and token_secret, you need to add a new Dropbox App in your account, and then you'll need to go through the oAuth authorization process
``` yaml
# app/config/config.yml
knp_gaufrette:
adapters:
foo:
dropbox:
api_id: acme_test.dropbox.api
```

In your AcmeTestBundle, add following service definitions:

``` yaml
# src/Acme/TestBundle/Resources/config/services.yml
parameters:
acme_test.dropbox.key: my_consumer_key
acme_test.dropbox.secret: my_consumer_secret
acme_test.dropbox.token: some_token
acme_test.dropbox.token_secret: some_token_secret

services:
acme_test.dropbox.oauth:
class: Dropbox_OAuth_Curl
arguments: [%acme_test.dropbox.key%, %acme_test.dropbox.secret%]
calls:
- [setToken, ["%acme_test.dropbox.token%", "%acme_test.dropbox.token_secret%"]]
acme_test.dropbox.api:
class: Dropbox_API
arguments: [@acme_test.dropbox.oauth, "sandbox"]
```

[gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette
4 changes: 3 additions & 1 deletion Resources/config/adapter_factories.xml
Expand Up @@ -53,7 +53,9 @@
<service id="knp_gaufrette.adapter.factory.cache" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\CacheAdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>

<service id="knp_gaufrette.adapter.factory.dropbox" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\DropboxAdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>
</services>

</container>
1 change: 1 addition & 0 deletions Resources/config/gaufrette.xml
Expand Up @@ -48,6 +48,7 @@
<service id="knp_gaufrette.filesystem_map" class="%knp_gaufrette.filesystem_map.class%">
<argument /> <!-- map of filesystems -->
</service>
<service id="knp_gaufrette.adapter.dropbox" class="Gaufrette\Adapter\Dropbox" abstract="true" public="false" />
</services>

</container>

0 comments on commit 9e70925

Please sign in to comment.