Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/Phaseolies/Console/Commands/DopparInstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Phaseolies\Console\Commands;

use Phaseolies\Application;
use Phaseolies\Console\Schedule\Command;
use Symfony\Component\Process\Process;

class DopparInstallCommand extends Command
{
/**
* The name of the console command.
*
* @var string
*/
protected $name = 'package:install';

/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Install doppar packages interactively with user prompts';

/**
* Execute the console command.
*
* @return int
*/
protected function handle(): int
{
if ($this->confirm('Do you want to install authentication?', false)) {
$this->installAuthentication();
}

if ($this->confirm('Do you want to install dopapr axios?', false)) {
$this->installAxios();
}

$this->info('Doppar installation completed.');
$this->newLine();
$this->info('Version: v' . Application::VERSION);

return 0;
}

/**
* Install authentication using php pool make:auth
*
* @return void
*/
protected function installAuthentication(): void
{
$this->info('Installing authentication...');

$process = new Process(['php', 'pool', 'make:auth']);
$process->setTimeout(300);

$process->run(function ($type, $buffer) {
echo $buffer;
});

if ($process->isSuccessful()) {
$this->info('Authentication installed successfully.');
}
}

/**
* Install doppar axios
*
* @return void
*/
protected function installAxios(): void
{
$this->info('Installing doppar axios...');

$process1 = new Process(['composer', 'require', 'doppar/axios']);
$process1->setTimeout(300);

$process1->run(function ($type, $buffer) {
echo $buffer;
});

$this->info('Axios installed successfully.');
}
}
1 change: 0 additions & 1 deletion src/Phaseolies/Console/Commands/MakeAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ protected function handle(): int
$this->displayInfo('🎉 Generated Files:');
$this->line('- Controllers: Login, Register, Home, Profile, 2FA');
$this->line('- Views: Login, Register, Home, Profile, Layout, 2FA');
$this->line('- Routes: Added to web.php');

return 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
namespace App\Http\Controllers;

use Phaseolies\Http\Response;
use Phaseolies\Utilities\Attributes\Middleware;
use Phaseolies\Utilities\Attributes\Route;
use App\Http\Middleware\Authenticate;
use App\Http\Controllers\Controller;

class HomeController extends Controller
{
/**
* Display the home page view
*
* @return Response
* @return \Phaseolies\Http\Response
*/
#[Middleware(Authenticate::class)]
#[Route('home', name: 'dashboard')]
#[Route('home', name: 'dashboard', middleware: ['auth'])]
public function __invoke(): Response
{
return view('home');
Expand Down
18 changes: 6 additions & 12 deletions src/Phaseolies/Console/Commands/stubs/auth/LoginController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ namespace App\Http\Controllers\Auth;
use Phaseolies\Http\Request;
use Phaseolies\Http\Response;
use Phaseolies\Support\Facades\Auth;
use Phaseolies\Utilities\Attributes\Middleware;
use Phaseolies\Utilities\Attributes\Route;
use Phaseolies\Http\Response\RedirectResponse;
use App\Models\User;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\GuestMiddleware;

class LoginController extends Controller
{
/**
* Show the login form view.
*
* @return Response
* @return \Phaseolies\Http\Response
*/
#[Middleware([GuestMiddleware::class])]
#[Route('login', name: 'login')]
#[Route('login', name: 'login', middleware: ['guest'])]
public function index(): Response
{
return view('auth.login');
Expand All @@ -31,10 +27,9 @@ class LoginController extends Controller
* Handle an authentication attempt.
*
* @param Request $request
* @return RedirectResponse
* @return \Phaseolies\Http\Response\RedirectResponse
*/
#[Middleware([GuestMiddleware::class])]
#[Route('login', name: 'login', methods: ['POST'])]
#[Route('login', name: 'login', methods: ['POST'], middleware: ['guest'])]
public function login(Request $request): RedirectResponse
{
$request->sanitize([
Expand All @@ -60,10 +55,9 @@ class LoginController extends Controller
/**
* Log the user out and redirect to login page.
*
* @return RedirectResponse
* @return \Phaseolies\Http\Response\RedirectResponse
*/
#[Middleware([Authenticate::class])]
#[Route('logout', name: 'logout', methods: ['POST'])]
#[Route('logout', name: 'logout', methods: ['POST'], middleware: ['auth'])]
public function logout(): RedirectResponse
{
Auth::logout();
Expand Down
128 changes: 128 additions & 0 deletions src/Phaseolies/Console/Schedule/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Phaseolies\Console\Schedule;

use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -338,4 +341,129 @@ protected function withTiming(callable $operation, ?string $successMessage = nul
return $result;
});
}


/**
* Prompt the user for confirmation.
*
* @param string $question
* @param bool $default
* @return bool
*/
protected function confirm(string $question, bool $default = true): bool
{
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion(
"<question>{$question}</question> " . ($default ? '[Y/n]' : '[y/N]') . " ",
$default
);

return $helper->ask($this->input, $this->output, $question);
}

/**
* Prompt the user for input.
*
* @param string $question
* @param string|null $default
* @return string
*/
protected function ask(string $question, ?string $default = null): string
{
$helper = $this->getHelper('question');

$questionText = "<question>{$question}</question>";
if ($default !== null) {
$questionText .= " [{$default}]";
}
$questionText .= " ";

$question = new Question($questionText, $default);

return $helper->ask($this->input, $this->output, $question);
}

/**
* Prompt the user for input but hide the answer.
*
* @param string $question
* @return string
*/
protected function secret(string $question): string
{
$helper = $this->getHelper('question');
$question = new Question("<question>{$question}</question> ");
$question->setHidden(true);
$question->setHiddenFallback(false);

return $helper->ask($this->input, $this->output, $question);
}

/**
* Give the user a single choice from an array of answers.
*
* @param string $question
* @param array $choices
* @param mixed $default
* @return mixed
*/
protected function choice(string $question, array $choices, $default = null)
{
$helper = $this->getHelper('question');
$question = new ChoiceQuestion("<question>{$question}</question>", $choices, $default);
$question->setErrorMessage('Choice %s is invalid.');

return $helper->ask($this->input, $this->output, $question);
}

/**
* Give the user multiple choices from an array of answers.
*
* @param string $question
* @param array $choices
* @param mixed $default
* @return array
*/
protected function multipleChoice(string $question, array $choices, $default = null): array
{
$helper = $this->getHelper('question');
$question = new ChoiceQuestion("<question>{$question}</question>", $choices, $default);
$question->setMultiselect(true);
$question->setErrorMessage('Choice %s is invalid.');

return $helper->ask($this->input, $this->output, $question);
}

/**
* Create a progress bar instance.
*
* @param int $max
* @return \Symfony\Component\Console\Helper\ProgressBar
*/
protected function createProgressBar(int $max = 0)
{
$progressBar = $this->getHelper('progress');

if (!$progressBar) {
throw new \RuntimeException('Progress bar helper not found.');
}

return $progressBar->create($this->output, $max);
}

/**
* Create a table instance.
*
* @return \Symfony\Component\Console\Helper\Table
*/
protected function createTable()
{
$table = $this->getHelper('table');

if (!$table) {
throw new \RuntimeException('Table helper not found.');
}

return $table->setStyle('default');
}
}
Loading