Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
OxCom committed Jul 7, 2023
1 parent 9d3c77f commit 1ff9a15
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea/

/vendor/
/var/

.phpunit.result.cache
composer.lock
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Andrey
Copyright (c) 2023 Andrey Afanasiev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 29 additions & 0 deletions composer.json
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"
}
}
32 changes: 32 additions & 0 deletions phpunit.xml
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>
39 changes: 39 additions & 0 deletions src/DependencyInjection/Configuration.php
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;
}
}
47 changes: 47 additions & 0 deletions src/DependencyInjection/SymfonyImageProxyExtension.php
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',
]);
}

}
8 changes: 8 additions & 0 deletions src/Providers/ImageProxyBuilderInterface.php
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;
}
17 changes: 17 additions & 0 deletions src/Providers/ImgProxy/Builder.php
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;
}
}
14 changes: 14 additions & 0 deletions src/Providers/ImgProxy/Security.php
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;
}
}
13 changes: 13 additions & 0 deletions src/Providers/Thumbor/Builder.php
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;
}
}
8 changes: 8 additions & 0 deletions src/Providers/Thumbor/Security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace SymfonyImageProxyBundle\Providers\Thumbor;

class Security
{

}
21 changes: 21 additions & 0 deletions src/Resources/config/services.yml
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%'
10 changes: 10 additions & 0 deletions src/SymfonyImageProxyBundle.php
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
{
}
17 changes: 17 additions & 0 deletions tests/DependencyInjection/ConfigurationTest.php
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);
}
}
31 changes: 31 additions & 0 deletions tests/Functional/app/AppKernel.php
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);
}
}
6 changes: 6 additions & 0 deletions tests/Functional/app/config.yml
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'

0 comments on commit 1ff9a15

Please sign in to comment.