diff --git a/.gitignore b/.gitignore index 363611e..056de66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /.idea -/composer.lock +build/ diff --git a/Controller/UploadController.php b/Controller/UploadController.php index c76d4e9..63074e0 100644 --- a/Controller/UploadController.php +++ b/Controller/UploadController.php @@ -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; @@ -41,7 +41,7 @@ * @package Glavweb\UploaderBundle * @author Andrey Nilov */ -class UploadController extends Controller +class UploadController extends AbstractController { /** * @var array @@ -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'); @@ -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'); @@ -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(); @@ -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); @@ -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); @@ -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); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 23be11b..6e654ac 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() @@ -80,8 +80,6 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('mappings') ->useAttributeAsKey('id') - ->isRequired() - ->requiresAtLeastOneElement() ->prototype('array') ->children() ->arrayNode('providers') diff --git a/DependencyInjection/GlavwebUploaderExtension.php b/DependencyInjection/GlavwebUploaderExtension.php index 08071b1..22721a5 100644 --- a/DependencyInjection/GlavwebUploaderExtension.php +++ b/DependencyInjection/GlavwebUploaderExtension.php @@ -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 @@ -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') - ]); - } } /** @@ -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) { diff --git a/Entity/Media.php b/Entity/Media.php index 8b4ab49..49e5925 100644 --- a/Entity/Media.php +++ b/Entity/Media.php @@ -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 diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php index b739f1a..b55d71f 100644 --- a/Event/PostUploadEvent.php +++ b/Event/PostUploadEvent.php @@ -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; diff --git a/Event/PreUploadEvent.php b/Event/PreUploadEvent.php index db0c561..c6cde86 100644 --- a/Event/PreUploadEvent.php +++ b/Event/PreUploadEvent.php @@ -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; diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php index bd53952..d900fc1 100644 --- a/Event/ValidationEvent.php +++ b/Event/ValidationEvent.php @@ -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; /** diff --git a/File/FileInterface.php b/File/FileInterface.php index 9a39466..a6c1262 100644 --- a/File/FileInterface.php +++ b/File/FileInterface.php @@ -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); } diff --git a/File/FilesystemFile.php b/File/FilesystemFile.php index f7fd383..731a46a 100644 --- a/File/FilesystemFile.php +++ b/File/FilesystemFile.php @@ -33,7 +33,6 @@ public function __construct(File $file, string $originalName = null) $file->getPathname(), $originalName ?? $file->getClientOriginalName(), $file->getClientMimeType(), - $file->getClientSize(), $file->getError(), true ); @@ -43,7 +42,6 @@ public function __construct(File $file, string $originalName = null) $file->getPathname(), $originalName ?? $file->getBasename(), $file->getMimeType(), - $file->getSize(), 0, true ); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index b673681..1da9820 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -83,6 +83,7 @@ + diff --git a/Storage/FlysystemStorage.php b/Storage/FlysystemStorage.php index e2a6c89..cc5d3d3 100644 --- a/Storage/FlysystemStorage.php +++ b/Storage/FlysystemStorage.php @@ -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; diff --git a/Util/MediaStructure.php b/Util/MediaStructure.php index ac915d4..01c63a6 100644 --- a/Util/MediaStructure.php +++ b/Util/MediaStructure.php @@ -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; /** @@ -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; } /** @@ -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); diff --git a/ci/integration-test/Dockerfile b/ci/integration-test/Dockerfile new file mode 100644 index 0000000..0e94c7a --- /dev/null +++ b/ci/integration-test/Dockerfile @@ -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\" }}}" \ No newline at end of file diff --git a/ci/integration-test/environment/config/bundles.php b/ci/integration-test/environment/config/bundles.php new file mode 100644 index 0000000..3166626 --- /dev/null +++ b/ci/integration-test/environment/config/bundles.php @@ -0,0 +1,8 @@ + ['all' => true], + Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Glavweb\UploaderBundle\GlavwebUploaderBundle::class => ['all' => true], +]; \ No newline at end of file diff --git a/ci/integration-test/run.sh b/ci/integration-test/run.sh new file mode 100755 index 0000000..cec8cea --- /dev/null +++ b/ci/integration-test/run.sh @@ -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 \ No newline at end of file diff --git a/ci/integration-test/scripts/copy.sh b/ci/integration-test/scripts/copy.sh new file mode 100644 index 0000000..cbe9223 --- /dev/null +++ b/ci/integration-test/scripts/copy.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -x + +cd .. + +rm -rf build/* +cp -r app/. build \ No newline at end of file diff --git a/ci/integration-test/scripts/run.sh b/ci/integration-test/scripts/run.sh new file mode 100644 index 0000000..44527a8 --- /dev/null +++ b/ci/integration-test/scripts/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -x +set -e + +composer require -n $PACKAGE_NAME + +php bin/phpunit + +../scripts/copy.sh diff --git a/composer.json b/composer.json index 57c17be..aedfc3c 100644 --- a/composer.json +++ b/composer.json @@ -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"