Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fomvasss committed Dec 13, 2017
0 parents commit 07428d0
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/vendor/
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,5 @@
# Changelog LaravelVariables

## 1.0.0 - 2017-12-12

- Initial release, make package
71 changes: 71 additions & 0 deletions README.md
@@ -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
```
43 changes: 43 additions & 0 deletions composer.json
@@ -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"
}
}
}
}
13 changes: 13 additions & 0 deletions config/variables.php
@@ -0,0 +1,13 @@
<?php

/*
|--------------------------------------------------------------------------
| Variables manager
|--------------------------------------------------------------------------
|
*/
return [
'cache' => [
'time' => 360,
]
];
34 changes: 34 additions & 0 deletions database/migrations/create_variables_table.php.stub
@@ -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');
}
}
26 changes: 26 additions & 0 deletions src/Commands/AllVariable.php
@@ -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);
}
}
36 changes: 36 additions & 0 deletions src/Commands/DeleteVariable.php
@@ -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')}`");
}
}
}
27 changes: 27 additions & 0 deletions src/Commands/GetVariable.php
@@ -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");
}
}
38 changes: 38 additions & 0 deletions src/Commands/SetVariable.php
@@ -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')}`");
}
}
}
16 changes: 16 additions & 0 deletions src/Facades/Variable.php
@@ -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);
}
}
16 changes: 16 additions & 0 deletions src/Variable.php
@@ -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',
];
}

0 comments on commit 07428d0

Please sign in to comment.