Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## dev-master

- Removed dependency on JMS Translation Bundle. If you have no other need for this bundle it can be removed by running
`composer remove jms/translation-bundle` and taking the relevant line out of `config/bundles.php` (or
`app/AppKernel.php` for projects that do not use Flex)

## [2.0.4](https://github.com/comur/ComurImageBundle/tree/2.0.4) (2019-05-31)
[Full Changelog](https://github.com/comur/ComurImageBundle/compare/2.0.3...2.0.4)

Expand Down
53 changes: 30 additions & 23 deletions Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

namespace Comur\ImageBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Contracts\Translation\TranslatorInterface;

use Symfony\Component\Finder\Finder;

use Comur\ImageBundle\Handler\UploadHandler;

class UploadController extends Controller
class UploadController extends AbstractController
{
private $translator;

public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

/**
* Save uploaded image according to comur_image field configuration
*
Expand Down Expand Up @@ -83,31 +91,31 @@ public function uploadImageAction(Request $request
$transDomain = $this->container->getParameter('comur_image.translation_domain');

$errorMessages = array(
1 => $this->get('translator')->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain),
2 => $this->get('translator')->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain),
3 => $this->get('translator')->trans('The uploaded file was only partially uploaded', array(), $transDomain),
4 => $this->get('translator')->trans('No file was uploaded', array(), $transDomain),
6 => $this->get('translator')->trans('Missing a temporary folder', array(), $transDomain),
7 => $this->get('translator')->trans('Failed to write file to disk', array(), $transDomain),
8 => $this->get('translator')->trans('A PHP extension stopped the file upload', array(), $transDomain),
'post_max_size' => $this->get('translator')->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain),
'max_file_size' => $this->get('translator')->trans('File is too big', array(), $transDomain),
'min_file_size' => $this->get('translator')->trans('File is too small', array(), $transDomain),
'accept_file_types' => $this->get('translator')->trans('Filetype not allowed', array(), $transDomain),
'max_number_of_files' => $this->get('translator')->trans('Maximum number of files exceeded', array(), $transDomain),
'max_width' => $this->get('translator')->trans('Image exceeds maximum width', array(), $transDomain),
'min_width' => $this->get('translator')->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain),
'max_height' => $this->get('translator')->trans('Image exceeds maximum height', array(), $transDomain),
'min_height' => $this->get('translator')->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain),
'abort' => $this->get('translator')->trans('File upload aborted', array(), $transDomain),
'image_resize' => $this->get('translator')->trans('Failed to resize image', array(), $transDomain),
1 => $this->translator->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain),
2 => $this->translator->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain),
3 => $this->translator->trans('The uploaded file was only partially uploaded', array(), $transDomain),
4 => $this->translator->trans('No file was uploaded', array(), $transDomain),
6 => $this->translator->trans('Missing a temporary folder', array(), $transDomain),
7 => $this->translator->trans('Failed to write file to disk', array(), $transDomain),
8 => $this->translator->trans('A PHP extension stopped the file upload', array(), $transDomain),
'post_max_size' => $this->translator->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain),
'max_file_size' => $this->translator->trans('File is too big', array(), $transDomain),
'min_file_size' => $this->translator->trans('File is too small', array(), $transDomain),
'accept_file_types' => $this->translator->trans('Filetype not allowed', array(), $transDomain),
'max_number_of_files' => $this->translator->trans('Maximum number of files exceeded', array(), $transDomain),
'max_width' => $this->translator->trans('Image exceeds maximum width', array(), $transDomain),
'min_width' => $this->translator->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain),
'max_height' => $this->translator->trans('Image exceeds maximum height', array(), $transDomain),
'min_height' => $this->translator->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain),
'abort' => $this->translator->trans('File upload aborted', array(), $transDomain),
'image_resize' => $this->translator->trans('Failed to resize image', array(), $transDomain),
);

$response->setCallback(function () use($handlerConfig, $errorMessages) {
new UploadHandler($handlerConfig, true, $errorMessages);
});

return $response->send();
return $response;
}

/**
Expand Down Expand Up @@ -430,8 +438,7 @@ private function resizeCropImage($destSrc, $imgSrc, $destX, $destY, $srcX, $srcY
*/
public function getTranslationCatalogue(Request $request) {
$transDomain = $this->container->getParameter('comur_image.translation_domain');
$translator = $this->container->get('translator');
$catalogue = $translator->getCatalogue($request->getLocale());
$catalogue = $this->translator->getCatalogue($request->getLocale());
$messages = $catalogue->all();

return $this->render('@ComurImage/translations.html.twig', array(
Expand Down
6 changes: 4 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('comur_image');
$treeBuilder = new TreeBuilder('comur_image');
$rootNode = method_exists($treeBuilder, "getRootNode")
? $treeBuilder->getRootNode()
: $treeBuilder->root('comur_image'); // BC layer for symfony/config 4.2 and older

$rootNode
->children()
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ return [
// ...
Comur\ImageBundle\ComurImageBundle::class => ['all' => true],
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
JMS\TranslationBundle\JMSTranslationBundle::class => ['all' => true],
];
```

Expand Down Expand Up @@ -165,7 +164,6 @@ class AppKernel extends Kernel
// ...
new Comur\ImageBundle\ComurImageBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new JMS\TranslationBundle\JMSTranslationBundle(),
];

// ...
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
comur_api_upload:
path: /upload #/{paramName}/{uploadUrl}/{webDir}/{minWidth}/{minHeight}
defaults: {_controller: "ComurImageBundle:Upload:uploadImage"}
defaults: {_controller: \Comur\ImageBundle\Controller\UploadController::uploadImageAction }
options:
expose: true

comur_api_crop:
path: /crop #/{uploadUrl}/{webDir}/{imageName}/{x}/{y}/{w}/{h}/{tarW}/{tarH}
defaults: {_controller: "ComurImageBundle:Upload:cropImage"}
defaults: {_controller: \Comur\ImageBundle\Controller\UploadController::cropImageAction }
options:
expose: true

comur_api_image_library:
path: /image-library
defaults: {_controller: "ComurImageBundle:Upload:getLibraryImages"}
defaults: {_controller: \Comur\ImageBundle\Controller\UploadController::getLibraryImagesAction }
options:
expose: true
5 changes: 5 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ services:
tags:
- { name: twig.extension }
arguments: ["%comur_image.cropped_image_dir%", "%comur_image.thumbs_dir%", "%comur_image.public_dir%", "%comur_image.translation_domain%", "%comur_image.gallery_dir%"]

Comur\ImageBundle\Controller\:
autowire: true
resource: '../../Controller'
tags: ['controller.service_arguments']
5 changes: 3 additions & 2 deletions Twig/ThumbExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
namespace Comur\ImageBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\TwigFilter;

class ThumbExtension extends AbstractExtension
class ThumbExtension extends AbstractExtension implements GlobalsInterface
{
protected $croppedDir;
protected $thumbsDir;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function getName()
return 'comur_thumb_extension';
}

public function getGlobals()
public function getGlobals(): array
{
return array('comur_translation_domain' => $this->transDomain);
}
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"require": {
"php": ">=7.1.3",
"ext-gd": "*",
"symfony/http-foundation": "~3.4 || ~4.2",
"symfony/form": "~3.4 || ~4.2",
"symfony/validator": "~3.4 || ~4.2",
"symfony/routing": "~3.4 || ~4.2",
"symfony/config": "~3.4 || ~4.2",
"symfony/twig-bridge": "~3.4 || ~4.2",
"twig/twig": "~2.5 || ~3.0",
"symfony/http-foundation": "~4.2 || ~5.0 || ~6.0",
"symfony/form": "~4.2 || ~5.0 || ~6.0",
"symfony/validator": "~4.2 || ~5.0 || ~6.0",
"symfony/routing": "~4.2 || ~5.0 || ~6.0",
"symfony/config": "~4.2 || ~5.0 || ~6.0",
"symfony/translation": "~4.2 || ~5.0 || ~6.0",
"symfony/twig-bridge": "~4.2 || ~5.0 || ~6.0",
"twig/twig": "^1.41 || ^2.10 || ~3.0",
"twig/extra-bundle": "@stable",
"friendsofsymfony/jsrouting-bundle": "@stable",
"jms/translation-bundle": "^1.2.2"
"friendsofsymfony/jsrouting-bundle": "@stable"
},
"autoload": {
"psr-4": {
Expand Down