Completed
Push — master ( 065cdd...96faaf )
by Alejandro
09:28
created

ImageFactory::__invoke()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 4
eloc 6
c 2
b 0
f 1
nc 2
nop 3
dl 0
loc 11
rs 9.2
1
<?php
2
namespace Shlinkio\Shlink\Common\Image;
3
4
use Interop\Container\ContainerInterface;
5
use Interop\Container\Exception\ContainerException;
6
use mikehaertl\wkhtmlto\Image;
7
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\Exception\ServiceNotFoundException;
9
use Zend\ServiceManager\Factory\FactoryInterface;
10
11
class ImageFactory implements FactoryInterface
12
{
13
    /**
14
     * Create an object
15
     *
16
     * @param  ContainerInterface $container
17
     * @param  string $requestedName
18
     * @param  null|array $options
19
     * @return object
20
     * @throws ServiceNotFoundException if unable to resolve the service.
21
     * @throws ServiceNotCreatedException if an exception is raised when
22
     *     creating a service.
23
     * @throws ContainerException if any other error occurs
24
     */
25
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
26
    {
27
        $config = $container->get('config')['phpwkhtmltopdf'];
28
        $image = new Image(isset($config['images']) ? $config['images'] : null);
29
30
        if (isset($options) && isset($options['url'])) {
31
            $image->setPage($options['url']);
32
        }
33
34
        return $image;
35
    }
36
}
37