-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9da7d66
Showing
12 changed files
with
719 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace lagbox\settings\Events; | ||
|
||
class SettingsSaved | ||
{ | ||
public function __construct() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.