Files
core/app/Console/Commands/SetTheme.php
T

56 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SetTheme extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'theme:set {theme_name}';
/**
* The console command description.
* @var string
*/
protected $description = 'Set theme for visitor area';
/**
* Create a new command instance.
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$theme = $this->argument('theme_name');
if (!is_dir(resource_path('views/visitor/' . $theme))) {
throw new NotFoundHttpException('Invalid theme ' . $theme . '!');
}
$env = file_get_contents(base_path('.env'));
$env = preg_replace('/THEME=(.+)/i', 'THEME=' . $theme, $env);
if (!Str::contains($env, 'THEME')) {
$env = sprintf("%s\nTHEME=%s\n", $env, $theme);
}
file_put_contents(base_path('.env'), $env);
$this->line('Theme successfully setup.');
}
}