-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathData.php
103 lines (95 loc) · 2.15 KB
/
Data.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Config;
/**
* Class Data
*/
class Data implements \Magento\FunctionalTestingFramework\Config\DataInterface
{
/**
* Configuration reader model
*
* @var \Magento\FunctionalTestingFramework\Config\ReaderInterface
*/
protected $reader;
/**
* Config data
*
* @var array
*/
protected $data = [];
/**
* Constructor
*
* @param \Magento\FunctionalTestingFramework\Config\ReaderInterface $reader
*/
public function __construct(\Magento\FunctionalTestingFramework\Config\ReaderInterface $reader)
{
$this->reader = $reader;
$this->load();
}
/**
* Merge config data to the object
*
* @param array $config
* @return void
*/
public function merge(array $config)
{
$this->data = array_replace_recursive($this->data, $config);
}
// @codingStandardsIgnoreStart
/**
* Get config value by key
*
* @param string $path
*
* @param null|mixed $default
* @return array|mixed|null
*/
public function get($path = null, $default = null)
{
if ($path === null) {
return $this->data;
}
$keys = explode('/', $path);
$data = $this->data;
foreach ($keys as $key) {
if (is_array($data) && array_key_exists($key, $data)) {
$data = $data[$key];
} else {
return $default;
}
}
return $data;
}
// @codingStandardsIgnoreEnd
/**
* Set name of the config file
*
* @param string $fileName
* @return self
*/
public function setFileName($fileName)
{
if ($fileName !== null) {
$this->reader->setFileName($fileName);
}
return $this;
}
/**
* Load config data
*
* @param string|null $scope
* @return void
*/
public function load($scope = null)
{
$this->merge(
$this->reader->read($scope)
);
}
}