From 6b4c3f5905be9c016960304bedc7f6a2216995f5 Mon Sep 17 00:00:00 2001 From: Emre YILMAZ Date: Fri, 25 Dec 2015 22:38:06 +0200 Subject: [PATCH] CDN Resolver. --- .../ResolverFactory/CdnResolverFactory.php | 51 +++++++++++++++++++ Resources/config/resolver_factories.yml | 6 ++- Resources/config/resolvers.yml | 6 +++ Service/Resolver/CdnResolver.php | 35 +++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 DependencyInjection/ResolverFactory/CdnResolverFactory.php create mode 100644 Service/Resolver/CdnResolver.php diff --git a/DependencyInjection/ResolverFactory/CdnResolverFactory.php b/DependencyInjection/ResolverFactory/CdnResolverFactory.php new file mode 100644 index 0000000..3a1d319 --- /dev/null +++ b/DependencyInjection/ResolverFactory/CdnResolverFactory.php @@ -0,0 +1,51 @@ +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']) + ; + } +} diff --git a/Resources/config/resolver_factories.yml b/Resources/config/resolver_factories.yml index 472b4aa..36e0a20 100644 --- a/Resources/config/resolver_factories.yml +++ b/Resources/config/resolver_factories.yml @@ -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: @@ -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 } diff --git a/Resources/config/resolvers.yml b/Resources/config/resolvers.yml index 8cb0aba..24cd314 100644 --- a/Resources/config/resolvers.yml +++ b/Resources/config/resolvers.yml @@ -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 @@ -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 diff --git a/Service/Resolver/CdnResolver.php b/Service/Resolver/CdnResolver.php new file mode 100644 index 0000000..3d289af --- /dev/null +++ b/Service/Resolver/CdnResolver.php @@ -0,0 +1,35 @@ +url = $url; + } + + /** + * {@inheritdoc} + */ + public function getUrl($key) + { + return $this->url . '/' . $key; + } +}