|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the m1\vars library |
|
5
|
|
|
* |
|
6
|
|
|
* (c) m1 <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @package m1/vars |
|
12
|
|
|
* @version 1.1.0 |
|
13
|
|
|
* @author Miles Croxford <[email protected]> |
|
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
|
15
|
|
|
* @license http://github.com/m1/vars/blob/master/LICENSE |
|
16
|
|
|
* @link http://github.com/m1/vars/blob/master/README.MD Documentation |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace M1\Vars\Variables; |
|
20
|
|
|
|
|
21
|
|
|
use \M1\Vars\Resource\AbstractResource; |
|
22
|
|
|
use M1\Vars\Traits\FileTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Stores the replacement variables |
|
26
|
|
|
* |
|
27
|
|
|
* @since 1.0.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
class ReplacementStore extends AbstractResource |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Basic file interaction logic |
|
33
|
|
|
*/ |
|
34
|
|
|
use FileTrait; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Creates new instance of VariableResource |
|
38
|
|
|
* |
|
39
|
|
|
* @param \M1\Vars\Vars $vars Instance of the calling Vars |
|
40
|
|
|
*/ |
|
41
|
82 |
|
public function __construct($vars) |
|
42
|
|
|
{ |
|
43
|
82 |
|
$this->vars = $vars; |
|
44
|
82 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Creates the replacement variable content from a file or array |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $replacements The replacements |
|
50
|
|
|
|
|
51
|
|
|
* @throws \RuntimeException If variable data is not array or a file |
|
52
|
|
|
* |
|
53
|
|
|
* @return array The replacement variables |
|
54
|
|
|
*/ |
|
55
|
4 |
|
public function load($replacements) |
|
56
|
|
|
{ |
|
57
|
4 |
|
if (is_array($replacements)) { |
|
58
|
2 |
|
$variables = $replacements; |
|
59
|
2 |
|
} elseif (is_file($replacements)) { |
|
60
|
1 |
|
$variables = $this->loadContent($replacements); |
|
61
|
|
|
} else { |
|
62
|
1 |
|
throw new \RuntimeException('Config replacements must be a array or a file'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
$this->content = $variables; |
|
|
|
|
|
|
66
|
3 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..