Skip to content

Commit

Permalink
make it working with all Symfony versions
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Jun 12, 2019
1 parent f6fac72 commit 5465e0e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ matrix:
- php: 7.2
env: SYMFONY_VERSION="~4.2.0" WITH_LIIP_IMAGINE=true
- php: 7.3
env: SYMFONY_VERSION="~4.2.0" WITH_LIIP_IMAGINE=true
env: SYMFONY_VERSION="~4.3.0" WITH_LIIP_IMAGINE=true
allow_failures:
- php: nightly

Expand All @@ -33,7 +33,6 @@ before_install:
- composer self-update
- phpenv config-rm xdebug.ini || true
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi
- if [ "$SYMFONY_VERSION" = "~3.4.0" ]; then composer remove symfony/event-dispatcher-contracts; fi
- if [ "$WITH_LIIP_IMAGINE" = true ] ; then composer require --no-update liip/imagine-bundle:"^1.7|^2.0"; fi;
- if [ "$VALIDATE_DOCS" = true ]; then composer require --dev --no-update kphoen/rusty dev-master; fi

Expand Down
3 changes: 2 additions & 1 deletion Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Vich\UploaderBundle\Event;

use Symfony\Component\EventDispatcher\Event as BaseEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
use Vich\UploaderBundle\Mapping\PropertyMapping;

Expand All @@ -11,7 +12,7 @@
*
* @author Kévin Gomez <[email protected]>
*/
if (class_exists(ContractEvent::class)) {
if ('42' !== Kernel::MAJOR_VERSION.Kernel::MINOR_VERSION && class_exists(ContractEvent::class)) {
class Event extends ContractEvent
{
protected $object;
Expand Down
5 changes: 3 additions & 2 deletions Handler/UploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Vich\UploaderBundle\Handler;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Event\Event;
use Vich\UploaderBundle\Event\Events;
use Vich\UploaderBundle\Injector\FileInjectorInterface;
Expand Down Expand Up @@ -105,7 +106,7 @@ public function remove($obj, string $fieldName): void

protected function dispatch(string $eventName, Event $event): void
{
if (Kernel::VERSION_ID >= 40300) {
if ('42' !== Kernel::MAJOR_VERSION.Kernel::MINOR_VERSION && class_exists(ContractEvent::class)) {
$this->dispatcher->dispatch($event, $eventName);
} else {
$this->dispatcher->dispatch($eventName, $event);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Handler/UploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Contracts\EventDispatcher\Event as ContractEvent;
use Vich\TestBundle\Entity\Article;
use Vich\UploaderBundle\Event\Event;
use Vich\UploaderBundle\Event\Events;
Expand Down Expand Up @@ -238,7 +239,7 @@ protected function validEvent()
protected function expectEvents(array $events): void
{
foreach ($events as $i => $event) {
if (Kernel::VERSION_ID >= 40300) {
if ('42' !== Kernel::MAJOR_VERSION.Kernel::MINOR_VERSION && class_exists(ContractEvent::class)) {
$this->dispatcher
->expects($this->at($i))
->method('dispatch')
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"symfony/config": "^3.4 || ^4.0",
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/event-dispatcher": "^3.4 || ^4.0",
"symfony/event-dispatcher-contracts": "^1.1",
"symfony/form": "^3.4.19 || ^4.0",
"symfony/http-foundation": "^3.4 || ^4.0",
"symfony/http-kernel": "^3.4 || ^4.0",
Expand Down

0 comments on commit 5465e0e

Please sign in to comment.