/
MixedEntry.php
55 lines (46 loc) · 1.25 KB
/
MixedEntry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Simply\Container\Entry;
use Psr\Container\ContainerInterface;
/**
* A standard container entry that may be any value or a closure used to determine that value.
*
* @author Riikka Kalliomäki <riikka.kalliomaki@gmail.com>
* @copyright Copyright (c) 2018 Riikka Kalliomäki
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class MixedEntry implements EntryInterface
{
/** @var mixed The value for the entry */
private $value;
/**
* MixedType constructor.
* @param mixed $value The value for the entry
*/
public function __construct($value)
{
$this->value = $value;
}
/** {@inheritdoc} */
public static function createFromCacheParameters(array $parameters): EntryInterface
{
return new static($parameters[0]);
}
/** {@inheritdoc} */
public function getCacheParameters(): array
{
return [$this->value];
}
/** {@inheritdoc} */
public function isFactory(): bool
{
return false;
}
/** {@inheritdoc} */
public function getValue(ContainerInterface $container)
{
if ($this->value instanceof \Closure) {
return ($this->value)($container);
}
return $this->value;
}
}