1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the `liip/LiipImagineBundle` project. |
5
|
|
|
* |
6
|
|
|
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Liip\ImagineBundle\Imagine\Filter\Loader; |
13
|
|
|
|
14
|
|
|
use Imagine\Image\ImageInterface; |
15
|
|
|
use Liip\ImagineBundle\Utility\OptionsResolver\OptionsResolver; |
16
|
|
|
use Liip\ImagineBundle\Exception\InvalidArgumentException; |
17
|
|
|
use Symfony\Component\OptionsResolver\Options; |
18
|
|
|
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface; |
19
|
|
|
|
20
|
|
|
class FlipFilterLoader implements LoaderInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @param ImageInterface $image |
24
|
|
|
* @param array $options |
25
|
|
|
* |
26
|
|
|
* @return ImageInterface |
27
|
|
|
*/ |
28
|
|
|
public function load(ImageInterface $image, array $options = array()) |
29
|
|
|
{ |
30
|
|
|
$options = $this->sanitizeOptions($options); |
31
|
|
|
|
32
|
|
|
return $options['axis'] === 'x' ? $image->flipHorizontally() : $image->flipVertically(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $options |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
private function sanitizeOptions(array $options) |
41
|
|
|
{ |
42
|
|
|
$resolver = new OptionsResolver(); |
|
|
|
|
43
|
|
|
$resolver->setDefault('axis', 'x'); |
44
|
|
|
$resolver->setAllowedValues('axis', array('x', 'horizontal', 'y', 'vertical')); |
45
|
|
|
$resolver->setNormalizer('axis', function (Options $options, $value) { |
46
|
|
|
return $value === 'horizontal' ? 'x' : ($value === 'vertical' ? 'y' : $value); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
return $resolver->resolve($options); |
51
|
|
|
} catch (ExceptionInterface $e) { |
52
|
|
|
throw new InvalidArgumentException('The "axis" option must be set to "x", "horizontal", "y", or "vertical".'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.