Skip to content

Commit

Permalink
Add symfony 5 support. Drop symfony 2 and 3 support. Change minimum p…
Browse files Browse the repository at this point in the history
…hp version to 7.2.5
  • Loading branch information
Nitro-N committed Jul 19, 2021
1 parent 2a1ba20 commit c1548ce
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.idea
/composer.lock
build/
18 changes: 9 additions & 9 deletions Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
use Glavweb\UploaderBundle\Response\Response as UploaderResponse;
use Glavweb\UploaderBundle\Response\ResponseInterface;
use Glavweb\UploaderBundle\UploadEvents;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
Expand All @@ -41,7 +41,7 @@
* @package Glavweb\UploaderBundle
* @author Andrey Nilov <[email protected]>
*/
class UploadController extends Controller
class UploadController extends AbstractController
{
/**
* @var array
Expand Down Expand Up @@ -114,7 +114,7 @@ public function uploadLinkAction(Request $request, $context)
*/
public function progressAction(Request $request)
{
$session = $this->container->get('session');
$session = $this->get('session');

$prefix = ini_get('session.upload_progress.prefix');
$name = ini_get('session.upload_progress.name');
Expand All @@ -135,7 +135,7 @@ public function progressAction(Request $request)
*/
public function cancelAction(Request $request)
{
$session = $this->container->get('session');
$session = $this->get('session');

$prefix = ini_get('session.upload_progress.prefix');
$name = ini_get('session.upload_progress.name');
Expand Down Expand Up @@ -284,7 +284,7 @@ protected function getFiles(FileBag $bag)
protected function doUpload(File $file, ResponseInterface $response, Request $request, $context)
{
/** @var UploaderManager $uploaderManager */
$uploaderManager = $this->container->get('glavweb_uploader.uploader_manager');
$uploaderManager = $this->get('glavweb_uploader.uploader_manager');
$mediaStructure = $this->get('glavweb_uploader.util.media_structure');
$config = $this->getConfig();

Expand Down Expand Up @@ -382,7 +382,7 @@ protected function dispatchPreUploadEvent(UploaderManager $uploaderManager,
$context)
{
$configContext = $uploaderManager->getContextConfig($context);
$dispatcher = $this->container->get('event_dispatcher');
$dispatcher = $this->get('event_dispatcher');

// dispatch pre upload event (both the specific and the general)
$event = new PreUploadEvent($uploadedFile, $response, $request, $context, $configContext);
Expand All @@ -409,7 +409,7 @@ protected function dispatchPostEvents(UploaderManager $uploaderManager,
$context)
{
$configContext = $uploaderManager->getContextConfig($context);
$dispatcher = $this->container->get('event_dispatcher');
$dispatcher = $this->get('event_dispatcher');

// dispatch post upload event (both the specific and the general)
$event = new PostUploadEvent($uploadedFile, $media, $response, $request, $context, $configContext);
Expand All @@ -426,7 +426,7 @@ protected function dispatchPostEvents(UploaderManager $uploaderManager,
protected function validate(UploaderManager $uploaderManager, FileInterface $file, Request $request, $context)
{
$configContext = $uploaderManager->getContextConfig($context);
$dispatcher = $this->container->get('event_dispatcher');
$dispatcher = $this->get('event_dispatcher');

// dispatch validation event (both the specific and the general)
$event = new ValidationEvent($file, $request, $configContext, $context);
Expand Down
6 changes: 2 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('glavweb_uploader');
$treeBuilder = new TreeBuilder('glavweb_uploader');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down Expand Up @@ -80,8 +80,6 @@ public function getConfigTreeBuilder()
->end()
->arrayNode('mappings')
->useAttributeAsKey('id')
->isRequired()
->requiresAtLeastOneElement()
->prototype('array')
->children()
->arrayNode('providers')
Expand Down
15 changes: 4 additions & 11 deletions DependencyInjection/GlavwebUploaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

namespace Glavweb\UploaderBundle\DependencyInjection;

use Liip\ImagineBundle\Templating\Helper\FilterHelper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration
Expand Down Expand Up @@ -44,12 +42,6 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

$container->setParameter('glavweb_uploader.config', $config);

if (class_exists(FilterHelper::class)) {
$container->getDefinition('glavweb_uploader.util.media_structure')->addMethodCall('setImagineHelper', [
new Reference('liip_imagine.templating.filter_helper')
]);
}
}

/**
Expand All @@ -59,8 +51,9 @@ public function load(array $configs, ContainerBuilder $container)
public function applyMappingsDefaults($config)
{
$defaults = $config['mappings_defaults'];
$mappings = $config['mappings'];

foreach ($config['mappings'] as &$contextConfig) {
foreach ($mappings as &$contextConfig) {

foreach ($contextConfig as $key => $value) {
if ((is_array($value) && empty($value)) || $value === null) {
Expand Down
1 change: 0 additions & 1 deletion Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Glavweb\UploaderBundle\Model\MediaInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Class Media
Expand Down
2 changes: 1 addition & 1 deletion Event/PostUploadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Glavweb\UploaderBundle\File\FileInterface;
use Glavweb\UploaderBundle\Model\MediaInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Glavweb\UploaderBundle\Response\ResponseInterface;

Expand Down
2 changes: 1 addition & 1 deletion Event/PreUploadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Glavweb\UploaderBundle\Event;

use Glavweb\UploaderBundle\File\FileInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
use Glavweb\UploaderBundle\Response\ResponseInterface;

Expand Down
2 changes: 1 addition & 1 deletion Event/ValidationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Glavweb\UploaderBundle\Event;

use Glavweb\UploaderBundle\File\FileInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down
2 changes: 1 addition & 1 deletion File/FileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ public function guessExtension();
*
* @return self A File object representing the new file
*/
public function move($directory, $name = null);
public function move(string $directory, string $name = null);
}
2 changes: 0 additions & 2 deletions File/FilesystemFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(File $file, string $originalName = null)
$file->getPathname(),
$originalName ?? $file->getClientOriginalName(),
$file->getClientMimeType(),
$file->getClientSize(),
$file->getError(),
true
);
Expand All @@ -43,7 +42,6 @@ public function __construct(File $file, string $originalName = null)
$file->getPathname(),
$originalName ?? $file->getBasename(),
$file->getMimeType(),
$file->getSize(),
0,
true
);
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

<service id="glavweb_uploader.util.media_structure" class="Glavweb\UploaderBundle\Util\MediaStructure" public="true">
<argument type="service" id="glavweb_uploader.media_helper" />
<argument type="service" id="liip_imagine.cache.manager" />
</service>

<service id="glavweb_uploader.command.clear_orphans_command" class="Glavweb\UploaderBundle\Command\ClearOrphansCommand">
Expand Down
1 change: 0 additions & 1 deletion Storage/FlysystemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Glavweb\UploaderBundle\Storage;

use Glavweb\UploaderBundle\Exception\CropImageException;
use Glavweb\UploaderBundle\File\FileInterface;
use Glavweb\UploaderBundle\File\FilesystemFile;
use Glavweb\UploaderBundle\File\FlysystemFile;
Expand Down
25 changes: 8 additions & 17 deletions Util/MediaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Glavweb\UploaderBundle\Exception\Exception;
use Glavweb\UploaderBundle\Helper\MediaHelper;
use Glavweb\UploaderBundle\Model\MediaInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Templating\Helper\FilterHelper;

/**
Expand All @@ -33,24 +34,18 @@ class MediaStructure
/**
* @var FilterHelper
*/
private $imagineHelper;
private $cacheManager;

/**
* MediaStructure constructor.
*
* @param MediaHelper $mediaHelper
* @param MediaHelper $mediaHelper
* @param CacheManager $cacheManager
*/
public function __construct(MediaHelper $mediaHelper)
public function __construct(MediaHelper $mediaHelper, CacheManager $cacheManager)
{
$this->mediaHelper = $mediaHelper;
}

/**
* @param FilterHelper $imagineHelper
*/
public function setImagineHelper($imagineHelper)
{
$this->imagineHelper = $imagineHelper;
$this->mediaHelper = $mediaHelper;
$this->cacheManager = $cacheManager;
}

/**
Expand Down Expand Up @@ -84,12 +79,8 @@ public function getMediaStructure(MediaInterface $media, $thumbnailFilter = null
$thumbnailPath = null;
if ($media->getThumbnailPath()) {
if ($thumbnailFilter) {
if (!$this->imagineHelper instanceof FilterHelper) {
throw new Exception('FilterHelper is not defined. You need use Liip\ImagineBundle.');
}

$thumbnailPath = $this->mediaHelper->getThumbnailPath($media, false);
$thumbnailPath = $this->imagineHelper->filter($thumbnailPath, $thumbnailFilter);
$thumbnailPath = $this->cacheManager->getBrowserPath($thumbnailPath, $thumbnailFilter);

} else {
$thumbnailPath = $this->mediaHelper->getThumbnailPath($media, $isAbsolute);
Expand Down
28 changes: 28 additions & 0 deletions ci/integration-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM php:7.2.5-cli

ARG BUNDLE_VERSION
ARG PACKAGE_NAME

RUN apt-get update && \
apt-get install -y \
unzip \
libzip-dev \
libpq-dev \
&& docker-php-ext-install zip pdo_pgsql

COPY --from=composer /usr/bin/composer /usr/bin/composer

WORKDIR /usr/src/

RUN composer create-project symfony/skeleton:"^5.3" app

COPY scripts/ scripts/
RUN chmod +x scripts/*

WORKDIR /usr/src/app

RUN composer require --dev phpunit/phpunit symfony/test-pack

COPY environment .

RUN composer config repositories.glavweb "{\"type\": \"path\", \"url\": \"../bundle\", \"options\": {\"versions\": { \"$PACKAGE_NAME\": \"$BUNDLE_VERSION\" }}}"
8 changes: 8 additions & 0 deletions ci/integration-test/environment/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Glavweb\UploaderBundle\GlavwebUploaderBundle::class => ['all' => true],
];
20 changes: 20 additions & 0 deletions ci/integration-test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -x
set -e

cd `dirname "$0"`

export BUNDLE_VENDOR=glavweb
export BUNDLE_NAME=uploader-bundle
export BUNDLE_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
export PACKAGE_NAME="$BUNDLE_VENDOR/$BUNDLE_NAME"
export IMAGE_NAME="$BUNDLE_VENDOR-$BUNDLE_NAME-test"

docker build -t $IMAGE_NAME --build-arg BUNDLE_VERSION=$BUNDLE_VERSION --build-arg PACKAGE_NAME=$PACKAGE_NAME .

docker run --tty -i --rm \
-v `pwd`/../../:/usr/src/bundle \
-v `pwd`/../../build/test:/usr/src/build \
-e PACKAGE_NAME="$PACKAGE_NAME" \
$IMAGE_NAME \
../scripts/run.sh
7 changes: 7 additions & 0 deletions ci/integration-test/scripts/copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

cd ..

rm -rf build/*
cp -r app/. build
9 changes: 9 additions & 0 deletions ci/integration-test/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -x
set -e

composer require -n $PACKAGE_NAME

php bin/phpunit

../scripts/copy.sh
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
}
],
"require": {
"php": "^7.2",
"symfony/http-foundation": "^2.7|^3.0|^4.0|^5.0",
"symfony/form": "^2.7|^3.0|^4.0|^5.0",
"twig/twig": "^2.12.1|^3.0",
"symfony/filesystem": "^2.7|^3.0|^4.0|^5.0",
"symfony/finder": "^2.7|^3.0|^4.0|^5.0",
"symfony/translation": "^2.7|^3.0|^4.0|^5.0"
"php": "^7.2.5",
"symfony/http-foundation": "^4.0|^5.0",
"symfony/form": "^4.0|^5.0",
"symfony/templating": "^4.0|^5.0",
"symfony/filesystem": "^4.0|^5.0",
"symfony/finder": "^4.0|^5.0",
"symfony/translation": "^4.0|^5.0",
"symfony/mime": "^4.0|^5.0",
"symfony/routing": "^4.0|^5.0",
"symfony/event-dispatcher": "^4.0|^5.0",
"doctrine/orm": "^2.3",
"doctrine/doctrine-bundle": "^2.0",
"liip/imagine-bundle": "^2.3.1"
},
"suggest": {
"oneup/flysystem-bundle": "Required for flysystem storage"
Expand Down

0 comments on commit c1548ce

Please sign in to comment.