2011-09-27 15:59:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
|
|
|
|
|
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
|
|
|
class AclAwareAmazonS3AdapterFactory implements AdapterFactoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2013-01-21 10:07:19 +00:00
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2011-09-27 15:59:14 +00:00
|
|
|
public function create(ContainerBuilder $container, $id, array $config)
|
|
|
|
{
|
2013-03-01 12:43:20 +00:00
|
|
|
$definition = $container
|
2011-09-27 15:59:14 +00:00
|
|
|
->setDefinition($id.'.delegate', new DefinitionDecorator('knp_gaufrette.adapter.amazon_s3'))
|
|
|
|
->addArgument(new Reference($config['amazon_s3_id']))
|
|
|
|
->addArgument($config['bucket_name'])
|
|
|
|
;
|
|
|
|
|
2013-02-22 16:29:35 +00:00
|
|
|
if (isset($config['options'])) {
|
|
|
|
$definition->addArgument($config['options']);
|
|
|
|
} elseif (isset($config['create'])) {
|
|
|
|
$definition->addArgument(array('create' => $config['create']));
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:59:14 +00:00
|
|
|
$def = $container
|
|
|
|
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.acl_aware_amazon_s3'))
|
|
|
|
->addArgument(new Reference($id.'.delegate'))
|
|
|
|
->addArgument(new Reference($config['amazon_s3_id']))
|
|
|
|
->addArgument($config['bucket_name'])
|
|
|
|
;
|
|
|
|
|
|
|
|
if (isset($config['acl'])) {
|
|
|
|
$def->addMethodCall('setAclConstant', array($config['acl']));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['users'])) {
|
|
|
|
$def->addMethodCall('setUsers', array($config['users']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-21 10:07:19 +00:00
|
|
|
* {@inheritDoc}
|
2011-09-27 15:59:14 +00:00
|
|
|
*/
|
|
|
|
public function getKey()
|
|
|
|
{
|
|
|
|
return 'acl_aware_amazon_s3';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-21 10:07:19 +00:00
|
|
|
* {@inheritDoc}
|
2011-09-27 15:59:14 +00:00
|
|
|
*/
|
|
|
|
public function addConfiguration(NodeDefinition $builder)
|
|
|
|
{
|
|
|
|
$builder
|
|
|
|
->validate()
|
|
|
|
->always(function($v) {
|
2011-10-14 23:25:07 +00:00
|
|
|
if (!empty($v['acl']) && !empty($v['users'])) {
|
2011-09-27 15:59:14 +00:00
|
|
|
throw new \Exception('"acl", and "users" cannot be set both at the same time.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $v;
|
|
|
|
})
|
|
|
|
->end()
|
|
|
|
->fixXmlConfig('user')
|
|
|
|
->children()
|
|
|
|
->scalarNode('amazon_s3_id')->isRequired()->cannotBeEmpty()->end()
|
|
|
|
->scalarNode('bucket_name')->isRequired()->cannotBeEmpty()->end()
|
|
|
|
->scalarNode('acl')->cannotBeEmpty()->end()
|
|
|
|
->arrayNode('users')
|
|
|
|
->prototype('array')
|
|
|
|
->validate()
|
|
|
|
->always(function($v) {
|
2011-10-14 23:25:07 +00:00
|
|
|
if (!empty($v['group']) === !empty($v['id'])) {
|
2011-09-27 15:59:14 +00:00
|
|
|
throw new \Exception('Either "group", or "id" must be set.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $v;
|
|
|
|
})
|
|
|
|
->end()
|
|
|
|
->children()
|
|
|
|
->scalarNode('group')->cannotBeEmpty()->end()
|
|
|
|
->scalarNode('id')->cannotBeEmpty()->end()
|
|
|
|
->scalarNode('permission')->isRequired()->cannotBeEmpty()->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->booleanNode('create')->defaultFalse()->end()
|
2013-06-23 18:43:17 +00:00
|
|
|
->arrayNode('options')
|
|
|
|
->children()
|
|
|
|
->booleanNode('create')
|
|
|
|
->defaultFalse()
|
|
|
|
->end()
|
|
|
|
->scalarNode('region')->end()
|
|
|
|
->scalarNode('directory')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2011-09-27 15:59:14 +00:00
|
|
|
->end()
|
|
|
|
;
|
|
|
|
}
|
2011-10-14 23:25:07 +00:00
|
|
|
}
|