Completed
Push — master ( 95a6e8...b8af6d )
by Filipe
07:12
created

Factory::setCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\Definition;
11
12
use Slick\Di\DefinitionInterface;
13
14
/**
15
 * Factory definition allows creation of object with a callable
16
 *
17
 * @package Slick\Di\Definition
18
 * @author  Filipe Silva <[email protected]>
19
 *
20
 * @property callable $callable The callable that will create the value
21
 */
22
class Factory extends AbstractDefinition implements DefinitionInterface
23
{
24
25
    /**
26
     * @readwrite
27
     * @var callable
28
     */
29
    protected $callable;
30
31
    /**
32
     * @read
33
     * @var array
34
     */
35
    protected $parameters;
36
37
    /**
38
     * Sets the callable for this factory
39
     *
40
     * @param callable $callable
41
     * @param array $parameters
42
     *
43
     * @return $this|self
44
     */
45 34
    public function setCallable(Callable $callable, array $parameters = [])
46
    {
47 34
        $this->callable = $callable;
48 34
        $this->parameters = $parameters;
49 34
        return $this;
50
    }
51
52
    /**
53
     * Resolves current definition and returns its value
54
     *
55
     * @return mixed
56
     */
57 8
    public function resolve()
58
    {
59 8
        return call_user_func_array($this->callable, $this->parameters);
60
    }
61
}
62