Skip to content

Commit

Permalink
run php-cs-fixer remove debug
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHippmann committed Jul 19, 2018
1 parent 7696b80 commit 62b8037
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 41 deletions.
5 changes: 3 additions & 2 deletions config/snippet-manager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
return array(

return [
/*
|--------------------------------------------------------------------------
| Routes group config
Expand All @@ -12,4 +13,4 @@
'prefix' => 'snippets',
'middleware' => 'auth',
],
);
];
14 changes: 6 additions & 8 deletions database/migrations/2017_07_28_162237_create_snippets_table.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php
use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateSnippetsTable extends Migration {
class CreateSnippetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ms_snippets', function(Blueprint $table)
{
Schema::create('ms_snippets', function (Blueprint $table) {
$table->increments('id');
$table->string('locale');
$table->string('namespace');
Expand All @@ -20,10 +19,9 @@ public function up()
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Expand Down
15 changes: 9 additions & 6 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

namespace Moonshiner\SnippetManager;

use Artisan;
use Cache;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

use Illuminate\Support\Collection;
use Moonshiner\SnippetManager\Models\Snippet;
use Artisan;
use App;
use Cache;

class Controller extends BaseController
{
/** @var \Moonshiner\SnippetManager\SnippetManager */
/** @var \Moonshiner\SnippetManager\SnippetManager */
protected $manager;

public function __construct(SnippetManager $manager)
{
$this->manager = $manager;
Expand All @@ -24,6 +23,7 @@ public function getView()
{
return view('snippet-manager::index');
}

public function index()
{
$allTranslations = Snippet::take(10)->get();
Expand All @@ -37,6 +37,7 @@ public function search()

return $allTranslations;
}

public function groups()
{
$namespaces = Snippet::select('namespace')->distinct()->get();
Expand All @@ -48,14 +49,15 @@ public function groups()
public function update(Request $request, Snippet $snippet)
{
$snippet->value = $request->input('value', '');
$path = [$snippet->locale,$snippet->namespace, $snippet->key];
$path = [$snippet->locale, $snippet->namespace, $snippet->key];
$storeKey = implode('/', $path);
Cache::flush($storeKey);
Cache::put($storeKey, $snippet->value);
$this->clearCache();

$snippet->save();
}

protected function loadLocales()
{
//Set the default locale as the first one.
Expand All @@ -67,6 +69,7 @@ protected function loadLocales()
$locales = $locales->all();
}
$locales = array_merge([config('app.locale')], $locales);

return array_unique($locales);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Models/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class Snippet extends Model
{

protected $table = 'ms_snippets';

protected $guarded = array('id', 'created_at', 'updated_at');

protected $guarded = ['id', 'created_at', 'updated_at'];
}
29 changes: 15 additions & 14 deletions src/SnippetManager.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php

namespace Moonshiner\SnippetManager;

use Moonshiner\SnippetManager\Manager;
use Illuminate\Foundation\Application;
use Moonshiner\SnippetManager\Models\Snippet;
use Cache;
use DB;
use Illuminate\Foundation\Application;
use Moonshiner\SnippetManager\Models\Snippet;

/**
*
*/
class SnippetManager
{
private $namespace = "";
private $namespace = '';
protected $app;

public function __construct(Application $app)
{
$this->app = $app;
Expand All @@ -29,18 +27,18 @@ public function setNamespace($namespace)

public function get($key, $default = '', $namespace = null)
{
if ($namespace !== null) {
if (null !== $namespace) {
$this->namespace = $namespace;
}

$path = [$this->app['config']['app.locale'], $this->namespace, $key];
$storeKey = implode('/', $path);
$manager = $this;
$namespace = $this->namespace;
xdebug_break();
$snippet = Cache::rememberForever($storeKey, function () use ($namespace, $key, $default, $manager) {
return $manager->fetch($namespace, $key, $default);
});

return $snippet;
}

Expand All @@ -50,29 +48,32 @@ public function fetch($namespace, $key = null, $default = '')
if ($key) {
$query->where('key', $key);
}
if ($namespace != '') {
if ('' != $namespace) {
$query->where('namespace', $namespace);
}
$query->where('locale', $this->app['config']['app.locale']);
if ($key) {
$snippetValue = $query->pluck('value')->first();
if (!$snippetValue) {
if (! $snippetValue) {
return $this->missingSnippet($namespace, $key, $default);
}

return $snippetValue;
}
$valuesByNamespace = [$namespace => $query->pluck('value', 'key')->toArray()];

return $valuesByNamespace;
}

public function missingSnippet($namespace, $key, $value)
{
Snippet::firstOrCreate(array(
Snippet::firstOrCreate([
'locale' => $this->app['config']['app.locale'],
'namespace' => $namespace,
'key' => $key,
'value' => $value
));
'value' => $value,
]);

return $value;
}
}
12 changes: 4 additions & 8 deletions src/SnippetManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@

namespace Moonshiner\SnippetManager;

use Blade;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;

use Blade;
use App;

class SnippetManagerServiceProvider extends ServiceProvider
{
protected $defer = false;

/**
* Register any package services.
*
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../config/snippet-manager.php';
$configPath = __DIR__.'/../config/snippet-manager.php';

$this->mergeConfigFrom($configPath, 'snippet-manager');

$this->publishes([$configPath => config_path('snippet-manager.php')], 'config');


$this->app->singleton('snippet.manager', function ($app) {
return new SnippetManager($app);
});
Expand Down Expand Up @@ -65,10 +60,11 @@ public function boot(Router $router)
$router->post('clearCache', 'Controller@clearCache');
});
}

public function provides()
{
return [
'snippet.manager'
'snippet.manager',
];
}
}

0 comments on commit 62b8037

Please sign in to comment.