|
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.0.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
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Stores the in-file variables |
|
25
|
|
|
* |
|
26
|
|
|
* @since 1.0.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
class VariableStore extends AbstractResource |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* The current prefix for the variable store |
|
32
|
|
|
* |
|
33
|
|
|
* @var string $current_prefix |
|
34
|
|
|
*/ |
|
35
|
|
|
private $current_prefix; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The relative prefix for the variable store |
|
39
|
|
|
* |
|
40
|
|
|
* @var string $path |
|
41
|
|
|
*/ |
|
42
|
|
|
private $prefix; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Creates a relative prefix for the store |
|
46
|
|
|
* |
|
47
|
|
|
* @param bool $relative Is the prefix relative |
|
48
|
|
|
*/ |
|
49
|
74 |
|
public function createPrefix($relative) |
|
50
|
|
|
{ |
|
51
|
74 |
|
if ($relative) { |
|
52
|
74 |
|
$this->prefix = (empty($this->current_prefix)) ? '' : $this->current_prefix; |
|
53
|
74 |
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
7 |
|
$this->prefix = ''; |
|
57
|
7 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Creates a new prefix name for the store |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $prefix The prefix for the store |
|
63
|
|
|
* @param string $key The key for the item |
|
64
|
|
|
* |
|
65
|
|
|
* @return string The new prefix |
|
66
|
|
|
*/ |
|
67
|
12 |
|
public function createPrefixName($prefix, $key) |
|
68
|
|
|
{ |
|
69
|
12 |
|
return $prefix.$key.'.'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the prefix |
|
74
|
|
|
* |
|
75
|
|
|
* @return string The prefix |
|
76
|
|
|
*/ |
|
77
|
72 |
|
public function getPrefix() |
|
78
|
|
|
{ |
|
79
|
72 |
|
return $this->prefix; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Sets the current prefix |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $prefix The new prefix |
|
86
|
|
|
*/ |
|
87
|
60 |
|
public function setCurrentPrefix($prefix) |
|
88
|
|
|
{ |
|
89
|
60 |
|
$this->current_prefix = $prefix; |
|
90
|
60 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|