Skip to content

Commit

Permalink
Merge pull request #1562 from liip/2-to-3
Browse files Browse the repository at this point in the history
merge 2.x to 3.x
  • Loading branch information
dbu authored Jan 12, 2024
2 parents c30119b + f6ad7b2 commit 65613e8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 10 deletions.
12 changes: 11 additions & 1 deletion doc/data-loaders-custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ path to the image and needs to return an instance of ``BinaryInterface``.
to sanitize this parameter in your loader to avoid exposing files outside
of your image collections.

You need to `configure a service`_ with your custom loader and tag it with
Register it: automatically
^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, your loader will be automatically registered as it implements the ``LoaderInterface``.

You will be able to reference and use your custom loader in your configuration by using its Fully Qualified Class Name.

Register it: manually
^^^^^^^^^^^^^^^^^^^^^

If you want to give it a different name you need to `configure a service`_ with your custom loader and tag it with
``liip_imagine.binary.loader``.

To register ``App\Service\MyCustomDataLoader`` with the name
Expand Down
14 changes: 12 additions & 2 deletions doc/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ The ``LoaderInterface`` has the method ``load``, which is provided an instance
of ``ImageInterface`` and an array of options. It must return an
``ImageInterface``.

You need to `configure a service`_ and tag it ``liip_imagine.filter.loader``.
Register it: automatically
^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, your filter will be automatically registered as it implements the ``LoaderInterface``.

You will be able to reference and use your custom filter when defining filter sets in your configuration by using its Fully Qualified Class Name.

Register it: manually
^^^^^^^^^^^^^^^^^^^^^

If you want to give it a different name you need to `configure a service`_ and tag it ``liip_imagine.filter.loader``.

To register a filter ``App\Service\MyCustomFilter`` as
``my_custom_filter``, use the following configuration:
Expand Down Expand Up @@ -124,7 +134,7 @@ to the image, by passing configuration as third parameter to ``applyFilter``:
public function filter(int $width, int $height) {
$filter = '...'; // Name of the `filter_set` in `config/packages/liip_imagine.yaml`
$path = '...'; // Path of the image, relative to `/public/`
if (!$this->cacheManager->isStored($path, $filter)) {
$binary = $this->dataManager->find($filter, $path);
Expand Down
6 changes: 3 additions & 3 deletions doc/optimizations/resolve-cache-images-in-background.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the result. Then it redirects the client to the generated image file.

This works without any further tooling. There are some important disadvantages however:

* Applying all the filters to an images can take a lot of time and memory;
* Applying all the filters to an image can take a lot of time and memory;
* The images have to be processed by the web server answering web requests. This increases the load
on the server and may affect performance;
* The resolve controller URL is different from the cached image URL. When the image needs to be
Expand All @@ -33,7 +33,7 @@ First, `install symfony/messenger`_ with composer:

.. code-block:: terminal
$ composer require symfony/messenger
composer require symfony/messenger
.. code-block:: yaml
Expand Down Expand Up @@ -70,7 +70,7 @@ We need to run at least one consumer for the messages:

.. code-block:: terminal
$ php bin/console messenger:consume liip_imagine --time-limit=3600 --memory-limit=256M
php bin/console messenger:consume liip_imagine --time-limit=3600 --memory-limit=256M
You can run the consumers on a separate machine, as long as it shares the same storage for the
cached images. In a cloud system, you could even scale consumers based on the queue size to get
Expand Down
12 changes: 11 additions & 1 deletion doc/post-processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@ for your custom post-processor.
}
}
You need to `configure a service`_ with your custom post-processor and tag it
Register it: automatically
^^^^^^^^^^^^^^^^^^^^^^^^^^

By default, your post-processor will be automatically registered as it implements the ``PostProcessorInterface``.

You will be able to reference and use your custom post-processor in your configuration by using its Fully Qualified Class Name.

Register it: manually
^^^^^^^^^^^^^^^^^^^^^

If you want to give it a different name you need to `configure a service`_ with your custom post-processor and tag it
with ``liip_imagine.filter.post_processor``.

To register ``App\Service\MyCustomPostProcessor`` with the name
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/FiltersCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(ContainerBuilder $container): void
$manager = $container->getDefinition('liip_imagine.filter.manager');

foreach ($tags as $id => $tag) {
$manager->addMethodCall('addLoader', [$tag[0]['loader'], new Reference($id)]);
$manager->addMethodCall('addLoader', [$tag[0]['loader'] ?? $id, new Reference($id)]);
$this->log($container, 'Registered filter loader: %s', $id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/LoadersCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(ContainerBuilder $container): void
$manager = $container->getDefinition('liip_imagine.data.manager');

foreach ($tags as $id => $tag) {
$manager->addMethodCall('addLoader', [$tag[0]['loader'], new Reference($id)]);
$manager->addMethodCall('addLoader', [$tag[0]['loader'] ?? $id, new Reference($id)]);
$this->log($container, 'Registered binary loader: %s', $id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(ContainerBuilder $container): void
$manager = $container->getDefinition('liip_imagine.filter.manager');

foreach ($tags as $id => $tag) {
$manager->addMethodCall('addPostProcessor', [$tag[0]['post_processor'], new Reference($id)]);
$manager->addMethodCall('addPostProcessor', [$tag[0]['post_processor'] ?? $id, new Reference($id)]);
$this->log($container, 'Registered filter post-processor: %s', $id);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/LiipImagineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Liip\ImagineBundle;

use Liip\ImagineBundle\Binary\Loader\LoaderInterface as BinaryLoaderInterface;
use Liip\ImagineBundle\DependencyInjection\Compiler\AssetsVersionCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\DriverCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
Expand All @@ -26,6 +27,8 @@
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory;
use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension;
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface as LoaderLoaderInterface;
use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down Expand Up @@ -55,5 +58,9 @@ public function build(ContainerBuilder $container): void
$extension->addLoaderFactory(new FileSystemLoaderFactory());
$extension->addLoaderFactory(new FlysystemLoaderFactory());
$extension->addLoaderFactory(new ChainLoaderFactory());

$container->registerForAutoconfiguration(LoaderLoaderInterface::class)->addTag('liip_imagine.filter.loader');
$container->registerForAutoconfiguration(PostProcessorInterface::class)->addTag('liip_imagine.filter.post_processor');
$container->registerForAutoconfiguration(BinaryLoaderInterface::class)->addTag('liip_imagine.binary.loader');
}
}
14 changes: 14 additions & 0 deletions tests/LiipImagineBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension;
use Liip\ImagineBundle\LiipImagineBundle;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down Expand Up @@ -60,6 +61,10 @@ public function testAddPasses(): void

return true;
}));
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);
Expand Down Expand Up @@ -97,6 +102,10 @@ public function testAddResolvers(): void
->method('getExtension')
->with('liip_imagine')
->willReturn($extensionMock);
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);
Expand Down Expand Up @@ -125,6 +134,11 @@ public function testAddLoaders(): void
->method('getExtension')
->with('liip_imagine')
->willReturn($extensionMock);
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);

Expand Down

0 comments on commit 65613e8

Please sign in to comment.