Completed
Push — master ( 0a7e57...033978 )
by Thomas Mauro
02:31
created

AbstractFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Facile\SentryModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use RuntimeException;
7
use Zend\ServiceManager\FactoryInterface;
8
9
/**
10
 * Class AbstractFactory.
11
 */
12
abstract class AbstractFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

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.

Loading history...
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
19
    /**
20
     * @var \Zend\Stdlib\AbstractOptions
21
     */
22
    protected $options;
23
24
    /**
25
     * @var string
26
     */
27
    protected $configKey = 'facile';
28
29
    /**
30
     * @param string $name
31
     */
32 2
    public function __construct($name)
33
    {
34 2
        $this->name = $name;
35 2
    }
36
37
    /**
38
     * @return string
39
     */
40 2
    public function getName()
41
    {
42 2
        return $this->name;
43
    }
44
45
    /**
46
     * Gets options from configuration based on name.
47
     *
48
     * @param ContainerInterface $container
49
     * @param string             $key
50
     * @param null|string        $name
51
     *
52
     * @return \Zend\Stdlib\AbstractOptions
53
     * @throws \Interop\Container\Exception\NotFoundException
54
     * @throws \Interop\Container\Exception\ContainerException
55
     *
56
     * @throws \RuntimeException
57
     */
58 2
    public function getOptions(ContainerInterface $container, $key, $name = null)
59
    {
60 2
        if ($name === null) {
61 2
            $name = $this->getName();
62 2
        }
63
64
        /** @var array $options */
65 2
        $options = $container->get('config');
66 2
        $options = $options[$this->configKey]['sentry'];
67 2
        $options = isset($options[$key][$name]) ? $options[$key][$name] : null;
68
69 2
        if (null === $options) {
70
            throw new RuntimeException(
71
                sprintf('Options with name "%s" could not be found in "%s.%s"', $name, $this->configKey, $key)
72
            );
73
        }
74
75 2
        $optionsClass = $this->getOptionsClass();
76
77 2
        return new $optionsClass($options);
78
    }
79
80
    /**
81
     * Get the class name of the options associated with this factory.
82
     *
83
     * @abstract
84
     *
85
     * @return string
86
     */
87
    abstract public function getOptionsClass();
88
}
89