Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lagbox committed Jun 20, 2016
0 parents commit 9da7d66
Show file tree
Hide file tree
Showing 12 changed files with 719 additions and 0 deletions.
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "lagbox/settings",
"description": "Laravel persistent settings",
"license": "MIT",
"keywords": ["laravel", "settings"],
"authors": [
{
"name": "lagbox",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.6",
"illuminate/support": "5.2.*",
"illuminate/cache": "5.2.*",
"illuminate/events": "5.2.*"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
},
"autoload": {
"psr-4": {
"lagbox\\settings\\": "src"
},
"files": [
"src/helpers.php"
]
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Another Laravel Settings Package

## No Available Yet - Under development - Just playing around

This will allow you to have persistent settings that you can control. A configuration file can be used as a set of defaults, fallbacks, for any settings and will be merged into the settings. There is caching involved to keep the DB out of the equation as much as possible and only gets invalidated when changes have been made to the settings.
11 changes: 11 additions & 0 deletions src/Events/SettingsSaved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace lagbox\settings\Events;

class SettingsSaved
{
public function __construct()
{

}
}
27 changes: 27 additions & 0 deletions src/Listeners/SettingsListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace lagbox\settings\Listeners;

use lagbox\settings\Setting;
use lagbox\settings\Events\SettingsSaved;
use Illuminate\Contracts\Cache\Repository as Cache;

class SettingsListener
{
protected $cache;

public function __construct(Cache $cache)
{
$this->cache = $cache;
}

/**
* Handle the post creation events.
*
* @param $event
*/
public function handle(SettingsSaved $event)
{
$this->cache->forget('settings');
}
}
36 changes: 36 additions & 0 deletions src/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace lagbox\settings;

use Cache;
use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
protected $fillable = [
'name', 'value'
];

public static function byName($name)
{
$vals = static::oldest('name')->name($name);

return is_array($name)
? $vals->lists('value', 'name')->all()
: $vals->value('value');
}

public static function destroyByName($names)
{
$ids = static::name($names)->lists('id')->all();

return static::destroy($ids);
}

public function scopeName($query, $name)
{
return is_array($name)
? $query->whereIn('name', $name)
: $query->where('name', $name);
}
}
Loading

0 comments on commit 9da7d66

Please sign in to comment.