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 07428d0
Showing
16 changed files
with
561 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 @@ | ||
/vendor/ |
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 @@ | ||
# Changelog LaravelVariables | ||
|
||
## 1.0.0 - 2017-12-12 | ||
|
||
- Initial release, make package |
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,71 @@ | ||
# Laravel Variables | ||
|
||
## Installation | ||
Run: | ||
```bash | ||
composer require fomvasss/laravel-variables | ||
``` | ||
--- | ||
For Laravel > 5.5 add to the service-providers list in app.php next | ||
providers: | ||
```php | ||
Fomvasss\Taxonomy\FieldFileServiceProvider::class, | ||
``` | ||
aliases: | ||
```php | ||
'Variable' => Fomvasss\Variable\Facades\Variable::class, | ||
``` | ||
--- | ||
|
||
Publish the config, migration: | ||
```bash | ||
php artisan vendor:publish --provider="Fomvasss\Variable\VariableServiceProvider" | ||
``` | ||
|
||
Run migrate: | ||
```bash | ||
php artisan migrate | ||
``` | ||
|
||
--- | ||
## Usage | ||
### Helpers | ||
- `var_all($locale = null)` | ||
- `var_get($name, $default = null, $locale = null)` | ||
- `var_set($name, $value = null, $locale = null)` | ||
- `var_delete($name, $locale = null)` | ||
- `var_set_array(array $attributes, $locale = null)` | ||
|
||
### Facade | ||
```php | ||
use Fomvasss\Variable\Facades\Variable; | ||
|
||
Variable::set('site_name', 'My Site); | ||
Variable::all(); | ||
Variable::get('site_name'); | ||
Variable::delete('site_name'); | ||
Variable::setArray(['titles' => 'TiTlE', 'slugan' => 'Lorem ipsun!']); | ||
``` | ||
You can use the localization vars: | ||
```php | ||
Variable::locale('en')->all(); | ||
Variable::locale('ru')->delete('site_name'); | ||
``` | ||
|
||
### DI VariableManagerContract class | ||
```php | ||
function (\Fomvasss\Variable\VariableManagerContract $mng) | ||
{ | ||
$mng->get('site_name'); | ||
} | ||
``` | ||
|
||
### Console command | ||
```bash | ||
variable:get-all # Get all variables | ||
variable:get # Get one variable | ||
variable:delete # Delete variable | ||
variable:set # Get all variables | ||
|
||
php artisan cache:forget fomvasss.variables.cache | ||
``` |
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,43 @@ | ||
{ | ||
"name": "fomvasss/laravel-variables", | ||
"description": "Management of variables/settings in Laravel projects", | ||
"type": "composer-package", | ||
"keywords": [ | ||
"fomvasss", | ||
"laravel", | ||
"variable", | ||
"settings" | ||
], | ||
"homepage": "https://github.com/fomvasss/laravel-variables", | ||
"authors": [ | ||
{ | ||
"name": "Vasyl Fomin", | ||
"email": "fomvasss@gmail.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php" : ">=7.0.0", | ||
"illuminate/support": "5.3.*|5.4.*|5.5.*", | ||
"illuminate/database": "5.3.*|5.4.*|5.5.*" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"src/helpers.php" | ||
], | ||
"psr-4": { | ||
"Fomvasss\\Variable\\": "src" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Fomvasss\\Variable\\VariableServiceProvider" | ||
], | ||
"aliases": { | ||
"Variable": "Fomvasss\\Variable\\Facade" | ||
} | ||
} | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Variables manager | ||
|-------------------------------------------------------------------------- | ||
| | ||
*/ | ||
return [ | ||
'cache' => [ | ||
'time' => 360, | ||
] | ||
]; |
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,34 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateVariablesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('variables', function (Blueprint $table) { | ||
$table->string('name')->index(); | ||
$table->binary('value')->nullable(); | ||
$table->string('locale')->nullable(); | ||
|
||
$table->unique(['name', 'locale']); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('variables'); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Fomvasss\Variable\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
/** | ||
* Class TaxonomyMigrate | ||
* | ||
* @package \Fomvasss\Taxonomy | ||
*/ | ||
class AllVariable extends Command | ||
{ | ||
protected $signature = 'variable:get-all | ||
{locale? : The locale variable}'; | ||
|
||
protected $description = 'Get all variables'; | ||
|
||
public function handle() | ||
{ | ||
$variableMng = app(\Fomvasss\Variable\VariableManagerContract::class); | ||
|
||
$variables = $variableMng->locale($this->argument('locale'))->all(); | ||
print_r($variables); | ||
} | ||
} |
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 Fomvasss\Variable\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
/** | ||
* Class TaxonomyMigrate | ||
* | ||
* @package \Fomvasss\Taxonomy | ||
*/ | ||
class DeleteVariable extends Command | ||
{ | ||
protected $signature = 'variable:delete | ||
{name : The name of the variable} | ||
{locale? : The locale variable}'; | ||
|
||
protected $description = 'Delete a variable'; | ||
|
||
public function handle() | ||
{ | ||
$variableMng = app(\Fomvasss\Variable\VariableManagerContract::class); | ||
|
||
$variable = $variableMng->locale($this->argument('locale'))->delete( | ||
$this->argument('name') | ||
); | ||
|
||
if ($variable) { | ||
$cacheName = 'fomvasss.variables.cache'; | ||
$this->call('cache:forget', ['key' => $cacheName]); | ||
$this->info("Variable delete successful `{$this->argument('name')}`"); | ||
} else { | ||
$this->info("Variable delete error `{$this->argument('name')}`"); | ||
} | ||
} | ||
} |
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 Fomvasss\Variable\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
/** | ||
* Class TaxonomyMigrate | ||
* | ||
* @package \Fomvasss\Taxonomy | ||
*/ | ||
class GetVariable extends Command | ||
{ | ||
protected $signature = 'variable:get | ||
{name : The name variable} | ||
{locale? : The locale variable}'; | ||
|
||
protected $description = 'Get one variable'; | ||
|
||
public function handle() | ||
{ | ||
$variableMng = app(\Fomvasss\Variable\VariableManagerContract::class); | ||
|
||
$variable = $variableMng->locale($this->argument('locale'))->get($this->argument('name'), ''); | ||
print_r($variable . "\n"); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Fomvasss\Variable\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
/** | ||
* Class TaxonomyMigrate | ||
* | ||
* @package \Fomvasss\Taxonomy | ||
*/ | ||
class SetVariable extends Command | ||
{ | ||
protected $signature = 'variable:set | ||
{name : The name of the variable} | ||
{value? : The value variable} | ||
{locale? : The locale variable}'; | ||
|
||
protected $description = 'Sett all variables'; | ||
|
||
public function handle() | ||
{ | ||
$variableMng = app(\Fomvasss\Variable\VariableManagerContract::class); | ||
|
||
$variable = $variableMng->locale($this->argument('locale'))->set( | ||
$this->argument('name'), | ||
$this->argument('value') | ||
); | ||
|
||
if ($variable) { | ||
$cacheName = 'fomvasss.variables.cache'; | ||
$this->call('cache:forget', ['key' => $cacheName]); | ||
$this->info("Variable set successful`{$this->argument('name')}`"); | ||
} else { | ||
$this->info("Variable set error `{$this->argument('name')}`"); | ||
} | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Fomvasss\Variable\Facades; | ||
|
||
use Fomvasss\Variable\VariableManagerContract; | ||
|
||
class Variable extends \Illuminate\Support\Facades\Facade | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return app(VariableManagerContract::class); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Fomvasss\Variable; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Variable extends Model | ||
{ | ||
public $timestamps = false; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'value', | ||
'locale', | ||
]; | ||
} |
Oops, something went wrong.