Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 authored Mar 19, 2024
1 parent 9996e02 commit ca20800
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

declare(strict_types=1);

use Console\ConsoleApplication;

/**
* Class Application
*
Expand All @@ -14,6 +12,8 @@
*/
final class App extends Container
{
private static ?App $instance = null;

/**
* Constructor for the Application class.
*/
Expand All @@ -22,10 +22,22 @@ public function __construct()
$this->loadEnv();
$this->configureEnvironment();
$this->registerComponents();
$this->setApp();
// $this->setApp();
$this->bootServices();
}

/**
* Singleton App
*/
public static function getInstance(): self
{
if (self::$instance === null) {
self::$instance = new self();
}

return self::$instance;
}

/**
* Set instance app
*/
Expand Down Expand Up @@ -111,7 +123,7 @@ public function getEnvironment()
*/
public function isLogged(): bool
{
return !empty($this->user);
return !empty ($this->user);
}

/**
Expand Down Expand Up @@ -186,7 +198,7 @@ public function getLocale(): string|false
throw new \Exception('The "Intl" extension is not enabled on this server');

$http = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '');
$locale = !empty($http) ? $http : 'en_US';
$locale = !empty ($http) ? $http : 'en_US';

return $locale;
}
Expand All @@ -205,8 +217,7 @@ private function generateTokens(): string
public function setCsrfCookie(string $csrfToken): void
{
$expiration = config('session.expiration');
// Convertir el tiempo de expiración a un entero
$expirationInSeconds = (int) ($expiration * 60); // Convertir minutos a segundos
$expirationInSeconds = (int) ($expiration * 60);
setcookie('csrfToken', $csrfToken, time() + $expirationInSeconds);
}

Expand All @@ -216,7 +227,7 @@ public function setCsrfCookie(string $csrfToken): void
*/
public function getCsrfToken(): string
{
return isset($_COOKIE['csrfToken']) ? $_COOKIE['csrfToken'] : $this->generateAndSetCsrfToken();
return isset ($_COOKIE['csrfToken']) ? $_COOKIE['csrfToken'] : $this->generateAndSetCsrfToken();
}

/**
Expand Down Expand Up @@ -256,9 +267,7 @@ public function user(string $value = null)
if (is_null($value))
return $this->get('user');

return $this
->get('user')
->{$value} ?? null;
return $this->get('user')->{$value} ?? null;
}

/**
Expand All @@ -285,20 +294,19 @@ public function __get(string $name)

/**
* Returns a new instance of the ConsoleApplication class
* @return ConsoleApplication A new instance of the ConsoleApplication class.
*/
public function createConsoleApplication()
{
static $console;
return $console ??= $this->get('console');
return $console ??= new \Console\ConsoleApplication;
}

/**
* Run the application.
**/
public function run(): void
{
(new Http\Router())
$this->get('router')
->openRoutesUser()
->dispatch();
}
Expand Down

0 comments on commit ca20800

Please sign in to comment.