Completed
Push — master ( 4edf95...ab1be0 )
by Андрей
02:23
created

AbstractResolverMap::setContextMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/entry-name-resolver
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\EntryNameResolver;
7
8
/**
9
 * Class AbstractResolverMap
10
 *
11
 * @package Nnx\EntryNameResolver
12
 */
13
abstract class AbstractResolverMap implements EntryNameResolverInterface
14
{
15
    /**
16
     * Карта используемая для определения имени сервиса в зависимости от контекста вызова
17
     *
18
     * 'имяСервиса' => [
19
     *      'contextKey' => 'имяСервисаДляЭтогоМодуля'
20
     * ]
21
     *
22
     * @var array
23
     */
24
    protected $contextMap = [];
25
26
    /**
27
     * @inheritdoc
28
     *
29
     * @param      $entryName
30
     * @param null $context
31
     *
32
     * @return null|string
33
     */
34
    public function resolveEntryNameByContext($entryName, $context = null)
35
    {
36
        $contextKey = $this->buildContextKey($context);
37
38
        $map = $this->getContextMap();
39
        $resolvedEntryName = null;
40
        if (array_key_exists($entryName, $map) && is_array($map[$entryName]) && array_key_exists($contextKey, $map[$entryName])) {
41
            $resolvedEntryName = $map[$entryName][$contextKey];
42
        }
43
44
        return $resolvedEntryName;
45
    }
46
47
    /**
48
     * Преобразует контекст в ключ
49
     *
50
     * @param $context
51
     *
52
     * @return mixed
53
     */
54
    abstract public function buildContextKey($context);
55
56
    /**
57
     * Возвращает карту используемую для определения имени сервиса в зависимости от контекста вызова
58
     *
59
     * @return array
60
     */
61
    public function getContextMap()
62
    {
63
        return $this->contextMap;
64
    }
65
66
    /**
67
     * Устанавливает карту используемую для определения имени сервиса в зависимости от контекста вызова
68
     *
69
     * @param array $contextMap
70
     *
71
     * @return $this
72
     */
73
    public function setContextMap($contextMap)
74
    {
75
        $this->contextMap = $contextMap;
76
77
        return $this;
78
    }
79
}
80