Skip to content

Commit

Permalink
Merge pull request #10 from delirehberi/master
Browse files Browse the repository at this point in the history
CDN Resolver.
  • Loading branch information
hmert committed Dec 28, 2015
2 parents a003aa9 + 6b4c3f5 commit 594d539
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
51 changes: 51 additions & 0 deletions DependencyInjection/ResolverFactory/CdnResolverFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php


/**
* @namespace
*/
namespace Jb\Bundle\FileUploaderBundle\DependencyInjection\ResolverFactory;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;

/**
* CdnResolverFactory
*
* @author jobou
*/
class CdnResolverFactory implements ResolverFactoryInterface
{
/**
* {@inheritdoc}
*/
public function getKey()
{
return 'cdn';
}

/**
* {@inheritdoc}
*/
public function addConfiguration(ArrayNodeDefinition $node)
{
$node
->children()
->scalarNode('url')->isRequired()->cannotBeEmpty()->end()
->end()
;
}

/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$container
->setDefinition($id, new DefinitionDecorator('jb_fileuploader.resolver.cdn.prototype'))
->setScope('request')
->addArgument($config['url'])
;
}
}
6 changes: 5 additions & 1 deletion Resources/config/resolver_factories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
jb_fileuploader.resolver_factory.asset.class: Jb\Bundle\FileUploaderBundle\DependencyInjection\ResolverFactory\AssetsResolverFactory
jb_fileuploader.resolver_factory.imagine.class: Jb\Bundle\FileUploaderBundle\DependencyInjection\ResolverFactory\ImagineResolverFactory
jb_fileuploader.resolver_factory.aws3.class: Jb\Bundle\FileUploaderBundle\DependencyInjection\ResolverFactory\Aws3ResolverFactory
jb_fileuploader.resolver_factory.cdn.class: Jb\Bundle\FileUploaderBundle\DependencyInjection\ResolverFactory\CdnResolverFactory

services:
jb_fileuploader.resolver_factory.asset:
Expand All @@ -13,8 +14,11 @@ services:
class: "%jb_fileuploader.resolver_factory.imagine.class%"
tags:
- { name: jb_fileuploader.resolver.factory }

jb_fileuploader.resolver_factory.aws3:
class: "%jb_fileuploader.resolver_factory.aws3.class%"
tags:
- { name: jb_fileuploader.resolver.factory }
jb_fileuploader.resolver_factory.cdn:
class: "%jb_fileuploader.resolver_factory.cdn.class%"
tags:
- { name: jb_fileuploader.resolver.factory }
6 changes: 6 additions & 0 deletions Resources/config/resolvers.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
jb_fileuploader.resolver.asset.prototype.class: Jb\Bundle\FileUploaderBundle\Service\Resolver\AssetsResolver
jb_fileuploader.resolver.aws3.prototype.class: Jb\Bundle\FileUploaderBundle\Service\Resolver\Aws3Resolver
jb_fileuploader.resolver.cdn.prototype.class: Jb\Bundle\FileUploaderBundle\Service\Resolver\CdnResolver
jb_fileuploader.resolver_chain.class: Jb\Bundle\FileUploaderBundle\Service\ResolverChain
jb_fileuploader.resolver.imagine.prototype.class: Jb\Bundle\FileUploaderBundle\Service\Resolver\ImagineCacheManagerResolver

Expand All @@ -10,6 +11,11 @@ services:
scope: request
abstract: true

jb_fileuploader.resolver.cdn.prototype:
class: %jb_fileuploader.resolver.cdn.prototype.class%
scope: request
abstract: true

jb_fileuploader.resolver.asset.prototype:
class: %jb_fileuploader.resolver.asset.prototype.class%
scope: request
Expand Down
35 changes: 35 additions & 0 deletions Service/Resolver/CdnResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Jb\Bundle\FileUploaderBundle\Service\Resolver;


/**
* AssetsResolver
*
* @author jobou
*/
class CdnResolver implements ResolverInterface
{

/**
* @var string
*/
protected $url;

/**
* Constructor
*
* @param string $url
*/
public function __construct($url)
{
$this->url = $url;
}

/**
* {@inheritdoc}
*/
public function getUrl($key)
{
return $this->url . '/' . $key;
}
}

0 comments on commit 594d539

Please sign in to comment.