Skip to content

Commit 8bf9ab7

Browse files
committed
Merge branch 'develop'
2 parents e3ca7d3 + f93a46c commit 8bf9ab7

17 files changed

+539
-518
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ branches:
66
language: php
77

88
php:
9+
- 5.3
910
- 5.4
1011
- 5.5
1112
- 5.6
@@ -16,9 +17,6 @@ env:
1617
- COMPOSER_ARGS=""
1718
- COMPOSER_ARGS="--prefer-lowest"
1819

19-
before_install:
20-
- composer self-update
21-
2220
install:
2321
- composer update ${COMPOSER_ARGS} --dev --no-interaction
2422

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
},
1919
"require-dev": {
2020
"mockery/mockery": "0.9.*",
21-
"illuminate/database": ">=4.1 <6.0"
21+
"illuminate/database": ">=4.1 <6.0",
22+
"illuminate/filesystem": ">=4.1 <6.0"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/ArrayUtil.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function get(array $data, $key, $default = null)
5858

5959
protected static function getArray(array $input, $keys, $default = null)
6060
{
61-
$output = [];
61+
$output = array();
6262

6363
foreach ($keys as $key) {
6464
static::set($output, $key, static::get($input, $key, $default));
@@ -108,7 +108,7 @@ public static function set(array &$data, $key, $value)
108108
// iterate through all of $segments except the last one
109109
foreach ($segments as $segment) {
110110
if (!array_key_exists($segment, $data)) {
111-
$data[$segment] = [];
111+
$data[$segment] = array();
112112
} else if (!is_array($data[$segment])) {
113113
throw new \UnexpectedValueException('Non-array segment encountered');
114114
}

src/DatabaseSettingStore.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function setTable($table)
6868
*/
6969
public function setConstraint(\Closure $callback)
7070
{
71+
$this->data = array();
72+
$this->loaded = false;
7173
$this->queryConstraint = $callback;
7274
}
7375

@@ -81,6 +83,32 @@ public function setExtraColumns(array $columns)
8183
$this->extraColumns = $columns;
8284
}
8385

86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function forget($key)
90+
{
91+
parent::forget($key);
92+
93+
// because the database store cannot store empty arrays, remove empty
94+
// arrays to keep data consistent before and after saving
95+
$segments = explode('.', $key);
96+
array_pop($segments);
97+
98+
while ($segments) {
99+
$segment = implode('.', $segments);
100+
101+
// non-empty array - exit out of the loop
102+
if ($this->get($segment)) {
103+
break;
104+
}
105+
106+
// remove the empty array and move on to the next segment
107+
$this->forget($segment);
108+
array_pop($segments);
109+
}
110+
}
111+
84112
/**
85113
* {@inheritdoc}
86114
*/

src/JsonSettingStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function setPath($path)
3232
{
3333
// If the file does not already exist, we will attempt to create it.
3434
if (!$this->files->exists($path)) {
35-
$result = $this->files->put($path, json_encode(array()));
35+
$result = $this->files->put($path, '{}');
3636
if ($result === false) {
3737
throw new \InvalidArgumentException("Could not write to $path.");
3838
}
@@ -50,10 +50,6 @@ public function setPath($path)
5050
*/
5151
protected function read()
5252
{
53-
if (!$this->files->exists($this->path)) {
54-
return array();
55-
}
56-
5753
$contents = $this->files->get($this->path);
5854

5955
$data = json_decode($contents, true);
@@ -70,7 +66,11 @@ protected function read()
7066
*/
7167
protected function write(array $data)
7268
{
73-
$contents = json_encode($data);
69+
if ($data) {
70+
$contents = json_encode($data);
71+
} else {
72+
$contents = '{}';
73+
}
7474

7575
$this->files->put($this->path, $contents);
7676
}

src/SettingStore.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ public function forget($key)
9595
}
9696
}
9797

98+
/**
99+
* Unset all keys in the settings data.
100+
*
101+
* @return void
102+
*/
103+
public function forgetAll()
104+
{
105+
$this->unsaved = true;
106+
$this->data = array();
107+
}
108+
98109
/**
99110
* Get all settings data.
100111
*

tests/ArrayUtilTest.php

Lines changed: 0 additions & 132 deletions
This file was deleted.

tests/DatabaseSettingFunctionalTest.php

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)