-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea/ | ||
|
||
/vendor/ | ||
/var/ | ||
|
||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "oxcom/symfony-imageproxy-bundle", | ||
"description": "Integration of the standalone server for resizing and converting remote images", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"SymfonyImageProxyBundle\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=8.1", | ||
"monolog/monolog": "^3.4", | ||
"symfony/config": "^6.3", | ||
"symfony/http-kernel": "^6.3", | ||
"twig/twig": "^3.6", | ||
"symfony/dependency-injection": "^6.3", | ||
"symfony/yaml": "^6.3" | ||
}, | ||
"require-dev": { | ||
"roave/security-advisories": "dev-latest", | ||
"symfony/test-pack": "^1.1", | ||
"symfony/framework-bundle": "^6.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" | ||
convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" | ||
bootstrap="vendor/autoload.php"> | ||
<coverage> | ||
<include> | ||
<directory>./src/</directory> | ||
</include> | ||
<exclude> | ||
<directory>./src/Resources/</directory> | ||
<directory>./tests/</directory> | ||
<directory>./vendor/</directory> | ||
</exclude> | ||
</coverage> | ||
<listeners> | ||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/> | ||
</listeners> | ||
<php> | ||
<ini name="error_reporting" value="-1"/> | ||
<env name="APP_DEBUG" value="false"/> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> | ||
<env name="XDEBUG_MODE" value="coverage"/> | ||
<server name="KERNEL_CLASS" value="Tests\Functional\app\AppKernel"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public const CONFIG_NAME = 'symfony_image_proxy'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$builder = new TreeBuilder(self::CONFIG_NAME); | ||
|
||
$builder->getRootNode() | ||
->children() | ||
->arrayNode('imgproxy') | ||
->children() | ||
->scalarNode('host')->defaultValue('localhost')->end() | ||
->scalarNode('key')->defaultValue('')->end() | ||
->scalarNode('salt')->defaultValue('')->end() | ||
->end() | ||
->end() | ||
->arrayNode('thumbor') | ||
->children() | ||
->scalarNode('host')->defaultValue('localhost')->end() | ||
->scalarNode('key')->defaultValue('')->end() | ||
->scalarNode('salt')->defaultValue('')->end() | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
return $builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use SymfonyImageProxyBundle\Providers\ImgProxy\Builder; | ||
use SymfonyImageProxyBundle\Providers\ImgProxy\Security; | ||
|
||
class SymfonyImageProxyExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yml'); | ||
|
||
$this->configureImgProxy($container, $config); | ||
} | ||
|
||
private function configureImgProxy(ContainerBuilder $container, array $config) | ||
{ | ||
$config = $config['imgproxy'] ?? []; | ||
|
||
if (empty($config)) { | ||
return; | ||
} | ||
|
||
$dSecurity = $container->getDefinition(Security::class); | ||
$dSecurity->setArguments([ | ||
$config['key'] ?? '', | ||
$config['salt'] ?? '' | ||
]); | ||
|
||
$dUrlBuilder = $container->getDefinition(Builder::class); | ||
$dUrlBuilder->setArguments([ | ||
new Reference(Security::class), | ||
$config['host'] ?? 'localhost', | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\Providers; | ||
|
||
interface ImageProxyBuilderInterface | ||
{ | ||
public function url(string $img, array $options = []): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\Providers\ImgProxy; | ||
|
||
use SymfonyImageProxyBundle\Providers\ImageProxyBuilderInterface; | ||
|
||
class Builder implements ImageProxyBuilderInterface | ||
{ | ||
public function __construct(private readonly Security $security, private readonly string $host) | ||
{ | ||
} | ||
|
||
public function url(string $img, array $options = []): string | ||
{ | ||
return $img; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\Providers\ImgProxy; | ||
class Security | ||
{ | ||
public function __construct(private readonly string $key, private readonly string $salt) | ||
{ | ||
} | ||
|
||
public function sign(string $img): string | ||
{ | ||
return $this->key . $img . $this->salt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\Providers\Thumbor; | ||
|
||
use SymfonyImageProxyBundle\Providers\ImageProxyBuilderInterface; | ||
|
||
class Builder implements ImageProxyBuilderInterface | ||
{ | ||
public function url(string $img, array $options = []): string | ||
{ | ||
return $img; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle\Providers\Thumbor; | ||
|
||
class Security | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
parameters: | ||
symfony_imageproxy.provider.imgproxy.security.class: SymfonyImageProxyBundle\Providers\ImgProxy\Security | ||
symfony_imageproxy.provider.imgproxy.builder.class: SymfonyImageProxyBundle\Providers\ImgProxy\Builder | ||
symfony_imageproxy.provider.thumbor.security.class: SymfonyImageProxyBundle\Providers\Thumbor\Security | ||
symfony_imageproxy.provider.thumbor.builder.class: SymfonyImageProxyBundle\Providers\Thumbor\Builder | ||
|
||
services: | ||
SymfonyImageProxyBundle\Providers\ImgProxy\Security: | ||
class: '%symfony_imageproxy.provider.imgproxy.security.class%' | ||
|
||
SymfonyImageProxyBundle\Providers\ImgProxy\Builder: | ||
public: true | ||
class: '%symfony_imageproxy.provider.imgproxy.builder.class%' | ||
|
||
|
||
SymfonyImageProxyBundle\Providers\Thumbor\Security: | ||
class: '%symfony_imageproxy.provider.thumbor.security.class%' | ||
|
||
SymfonyImageProxyBundle\Providers\Thumbor\Builder: | ||
public: true | ||
class: '%symfony_imageproxy.provider.thumbor.builder.class%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace SymfonyImageProxyBundle; | ||
|
||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class SymfonyImageProxyBundle extends Bundle | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\DependencyInjection; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use SymfonyImageProxyBundle\Providers\ImgProxy\Builder; | ||
|
||
class ConfigurationTest extends KernelTestCase | ||
{ | ||
public function testParameters(): void | ||
{ | ||
static::bootKernel(); | ||
|
||
$container = static::$kernel->getContainer(); | ||
$builder = $container->get(Builder::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Tests\Functional\app; | ||
|
||
use Psr\Log\NullLogger; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use SymfonyImageProxyBundle\SymfonyImageProxyBundle; | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles(): array | ||
{ | ||
return [ | ||
new FrameworkBundle(), | ||
new SymfonyImageProxyBundle(), | ||
]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
$loader->load(__DIR__ . '/config.yml'); | ||
} | ||
|
||
protected function build(ContainerBuilder $container): void | ||
{ | ||
$container->register('logger', NullLogger::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
symfony_image_proxy: | ||
imgproxy: | ||
host: 'conv.awesome.com' | ||
key: '113' | ||
salt: '456' | ||
|