Skip to content

Commit

Permalink
version is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
robinNcode committed Jun 1, 2023
1 parent f8677e7 commit ed9ff45
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
20 changes: 17 additions & 3 deletions src/Commands/ControllerPublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct()
*/
public function handle(): void
{
if(!$this->generateController()){
if(!$this->generateController() && !$this->generateAppController()){
$this->error('The controller was not generated!');
}
else{
Expand Down Expand Up @@ -59,16 +59,30 @@ public function generateController(): bool
public function generateRoute(): bool
{
$app_folder = base_path() . '/routes/';
$package_folder = __DIR__ . '/../routes/';

// Read the existing contents of web.php
$existingContents = $this->fileSystem->get($app_folder . 'web.php');

// Append new lines to the existing contents
$newContents = $existingContents . "\n\n" . "Route::get('/onubadok/change/{lang}', 'OnubadokController@change');";
$newContents = $existingContents . "\n\n" . "Route::get('onubadok/change/{lang}', 'App\Http\Controllers\OnubadokController@change');";

// Generate the updated file
return $this->fileSystem->put($app_folder . 'web.php', $newContents);
}

/**
* To generate the AppController ...
* @throws FileNotFoundException
*/
public function generateAppController(): bool
{
$app_folder = app_path() . '/Http/Controllers/';
$package_folder = __DIR__ . '/../Controllers/';

$contents = $this->fileSystem->get($package_folder . 'Controller.php');

// generate the file
return $this->fileSystem->put($app_folder . 'Controller.php', $contents);
}

}
12 changes: 6 additions & 6 deletions src/Commands/OnubadokCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handle(): void
$language = $this->argument('language');

if ($language == null) {
$this->error('Please provide a language code');
$this->error('Please provide a language code.');
} else {
$folders = ['en', $language];
$this->generating($folders, $base_folder);
Expand All @@ -44,17 +44,17 @@ protected function generating($folders, $base_folder): void
// Check if the directory already exists then override the base folder
foreach ($folders as $language) {
if ($this->fileSystem->exists($base_folder . '/' . $language)) {
$this->info('The directory already exists');
$this->info('Overriding the base folder');
$this->info('The directory already exists.');
$this->info('Overriding the base folder.');
$base_folder = $base_folder . '/' . $language;
break;
} else {
// Creating app/lang/en directory and generating files
$this->info('Generating files in the app/lang/' . $language . ' directory ...');
$this->info('Generating files in the app/lang/' . $language . ' directory...');
if ($this->generateFilesWithContents($base_folder, $language)) {
$this->info('The files were generated successfully in the app/lang/' . $language . ' directory');
$this->info('The files were generated successfully in the app/lang/' . $language . ' directory.');
} else {
$this->error('The files were not generated');
$this->error('The files were not generated.');
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Robinncode\Onubadok\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\App;

/**
* Class Controller
* @package App\Http\Controllers
* @generated_by Robinncode\Onubadok
* @property string $language
*/
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;

public function __construct()
{
$this->middleware(function ($request, $next) {
if (session()->has('language')) {
App::setLocale(session()->get('language'));
}
return $next($request);
});
}
}
4 changes: 1 addition & 3 deletions src/Controllers/OnubadokController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class OnubadokController extends Controller
public function change($language): RedirectResponse
{
session(['language' => $language]);
app()->setLocale($language);

return redirect()->back();
return redirect()->to('/');
}
}
2 changes: 2 additions & 0 deletions src/lang/bn/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
'Bank Information' => 'ব্যাঙ্কের তথ্য',
'Add Bank' => 'ব্যাঙ্ক যোগ',
'Bank Info Update' => 'ব্যাঙ্ক তথ্য আপডেট',

'Documentation' => 'ডকুমেন্টেশন',
];
2 changes: 2 additions & 0 deletions src/lang/en/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
'Bank Information' => 'Bank Information',
'Add Bank' => 'Add Bank',
'Bank Info Update' => 'Bank Info Update',

'Documentation' => 'Documentation',
];

0 comments on commit ed9ff45

Please sign in to comment.