Skip to content

Commit

Permalink
Compatibility with Symfony4 (thanks to Arkounay, see #110 & #111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed May 17, 2018
1 parent ffbca47 commit 54ff441
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions Resources/config/services.yml
Expand Up @@ -12,6 +12,7 @@ services:
- '%gregwar_image.cache_dir_mode%'
- '%image.handler.class%'
- '@service_container'
- '@assets.packages'
- '@file_locator'
- '%gregwar_image.throw_exception%'
- '%gregwar_image.fallback_image%'
Expand Down
11 changes: 9 additions & 2 deletions Services/ImageHandling.php
Expand Up @@ -5,6 +5,7 @@
use Gregwar\ImageBundle\ImageHandler;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand All @@ -30,6 +31,11 @@ class ImageHandling
*/
private $container;

/**
* @var Packages
*/
private $assetsPackages;

/**
* @var string
*/
Expand All @@ -54,7 +60,7 @@ class ImageHandling
* @param bool $throwException
* @param string $fallbackImage
*/
public function __construct($cacheDirectory, $cacheDirMode, $handlerClass, ContainerInterface $container, $fileLocator, $throwException, $fallbackImage)
public function __construct($cacheDirectory, $cacheDirMode, $handlerClass, ContainerInterface $container, Packages $assetsPackages, $fileLocator, $throwException, $fallbackImage)
{
if (!$fileLocator instanceof FileLocatorInterface && $fileLocator instanceof KernelInterface) {
throw new \InvalidArgumentException(
Expand All @@ -76,6 +82,7 @@ public function __construct($cacheDirectory, $cacheDirMode, $handlerClass, Conta
$this->cacheDirMode = intval($cacheDirMode);
$this->handlerClass = $handlerClass;
$this->container = $container;
$this->assetsPackages = $assetsPackages;
$this->fileLocator = $fileLocator;
$this->throwException = $throwException;
$this->fallbackImage = $fallbackImage;
Expand Down Expand Up @@ -150,7 +157,7 @@ private function createInstance($file, $w = null, $h = null)
});
} else {
$image->setFileCallback(function ($file) use ($container) {
return $container->get('assets.packages')->getUrl($file);
return $this->assetsPackages->getUrl($file);
});
}

Expand Down
12 changes: 8 additions & 4 deletions composer.json
Expand Up @@ -15,17 +15,21 @@
"require": {
"php": ">=5.3.3",
"ext-gd": "*",
"symfony/framework-bundle": "^2.3 || ^3.0",
"symfony/framework-bundle": "^2.3 || ^3.0 || ^4.0",
"twig/twig": "^1.12 || ^2.0",
"gregwar/image": "2.*"
},
"require-dev": {
"sllh/php-cs-fixer-styleci-bridge": "~1.1"
},
"autoload": {
"psr-0": {
"Gregwar\\ImageBundle": ""
"psr-4": {
"Gregwar\\ImageBundle\\": ""
}
},
"target-dir": "Gregwar/ImageBundle"
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
}
}

1 comment on commit 54ff441

@aimiliano
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this commit breaks with symfony 2.x projects
with error:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "image.handling" has a dependency on a non-existent service "assets.packages".

Please sign in to comment.