|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace Core\Factory\Service; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Options\ImagineOptions; |
|
14
|
|
|
use Interop\Container\ContainerInterface; |
|
15
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
16
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Factory for Imagine service. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
22
|
|
|
* @since 0.29 |
|
23
|
|
|
*/ |
|
24
|
|
|
class ImagineFactory implements FactoryInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
* |
|
29
|
|
|
* @param ContainerInterface $container |
|
30
|
|
|
* @param string $requestedName |
|
31
|
|
|
* @param array $options |
|
|
|
|
|
|
32
|
|
|
* |
|
33
|
|
|
* @return \Imagine\Image\ImagineInterface |
|
34
|
|
|
* @throws \UnexpectedValueException |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
37
|
|
|
{ |
|
38
|
|
|
$options = $container->get(ImagineOptions::class); |
|
39
|
|
|
$lib = $options->getImageLib(); |
|
40
|
|
|
|
|
41
|
|
|
switch ($lib) { |
|
42
|
|
|
default: |
|
43
|
|
|
throw new \UnexpectedValueException('Unsupported image library specified.'); |
|
44
|
|
|
break; |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
case ImagineOptions::LIB_GD: |
|
47
|
|
|
case ImagineOptions::LIB_IMAGICK: |
|
48
|
|
|
case ImagineOptions::LIB_GMAGICK: |
|
49
|
|
|
$imagineClass = '\Imagine\\' . $lib . '\Imagine'; |
|
50
|
|
|
$imagine = new $imagineClass; |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $imagine; |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Create service |
|
60
|
|
|
* |
|
61
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Imagine\Image\ImagineInterface |
|
64
|
|
|
*/ |
|
65
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this($serviceLocator, 'Imagine'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.