Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
anlutro committed May 14, 2015
2 parents e3ca7d3 + f93a46c commit 8bf9ab7
Show file tree
Hide file tree
Showing 17 changed files with 539 additions and 518 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ branches:
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
Expand All @@ -16,9 +17,6 @@ env:
- COMPOSER_ARGS=""
- COMPOSER_ARGS="--prefer-lowest"

before_install:
- composer self-update

install:
- composer update ${COMPOSER_ARGS} --dev --no-interaction

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"require-dev": {
"mockery/mockery": "0.9.*",
"illuminate/database": ">=4.1 <6.0"
"illuminate/database": ">=4.1 <6.0",
"illuminate/filesystem": ">=4.1 <6.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/ArrayUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function get(array $data, $key, $default = null)

protected static function getArray(array $input, $keys, $default = null)
{
$output = [];
$output = array();

foreach ($keys as $key) {
static::set($output, $key, static::get($input, $key, $default));
Expand Down Expand Up @@ -108,7 +108,7 @@ public static function set(array &$data, $key, $value)
// iterate through all of $segments except the last one
foreach ($segments as $segment) {
if (!array_key_exists($segment, $data)) {
$data[$segment] = [];
$data[$segment] = array();
} else if (!is_array($data[$segment])) {
throw new \UnexpectedValueException('Non-array segment encountered');
}
Expand Down
28 changes: 28 additions & 0 deletions src/DatabaseSettingStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function setTable($table)
*/
public function setConstraint(\Closure $callback)
{
$this->data = array();
$this->loaded = false;
$this->queryConstraint = $callback;
}

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

/**
* {@inheritdoc}
*/
public function forget($key)
{
parent::forget($key);

// because the database store cannot store empty arrays, remove empty
// arrays to keep data consistent before and after saving
$segments = explode('.', $key);
array_pop($segments);

while ($segments) {
$segment = implode('.', $segments);

// non-empty array - exit out of the loop
if ($this->get($segment)) {
break;
}

// remove the empty array and move on to the next segment
$this->forget($segment);
array_pop($segments);
}
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 6 additions & 6 deletions src/JsonSettingStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setPath($path)
{
// If the file does not already exist, we will attempt to create it.
if (!$this->files->exists($path)) {
$result = $this->files->put($path, json_encode(array()));
$result = $this->files->put($path, '{}');
if ($result === false) {
throw new \InvalidArgumentException("Could not write to $path.");
}
Expand All @@ -50,10 +50,6 @@ public function setPath($path)
*/
protected function read()
{
if (!$this->files->exists($this->path)) {
return array();
}

$contents = $this->files->get($this->path);

$data = json_decode($contents, true);
Expand All @@ -70,7 +66,11 @@ protected function read()
*/
protected function write(array $data)
{
$contents = json_encode($data);
if ($data) {
$contents = json_encode($data);
} else {
$contents = '{}';
}

$this->files->put($this->path, $contents);
}
Expand Down
11 changes: 11 additions & 0 deletions src/SettingStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ public function forget($key)
}
}

/**
* Unset all keys in the settings data.
*
* @return void
*/
public function forgetAll()
{
$this->unsaved = true;
$this->data = array();
}

/**
* Get all settings data.
*
Expand Down
132 changes: 0 additions & 132 deletions tests/ArrayUtilTest.php

This file was deleted.

99 changes: 0 additions & 99 deletions tests/DatabaseSettingFunctionalTest.php

This file was deleted.

Loading

0 comments on commit 8bf9ab7

Please sign in to comment.