Files
nexusphp/bootstrap/app.php
Qi HU d9f1612e8e fix: Fix duplicate includes in app.php
When we use `php artisan optimize` command, it will cause duplicate includes:
```
PHP Fatal error:  Cannot redeclare function get_global_sp_state() (previously declared in include/globalfunctions.php:3) in include/globalfunctions.php on line 3

   Symfony\Component\ErrorHandler\Error\FatalError

  Cannot redeclare function get_global_sp_state() (previously declared in include/globalfunctions.php:3)

  at include/globalfunctions.php:3
      1▕ <?php
      2▕
  ➜   3▕ function get_global_sp_state()
      4▕ {
      5▕        static $global_promotion_state;
      6▕        $cacheKey = \App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY;
      7▕        if (is_null($global_promotion_state)) {
      8▕         $row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
      9▕             return \Nexus\Database\NexusDB::getOne('torrents_state', 1);

   Whoops\Exception\ErrorException

  Cannot redeclare function get_global_sp_state() (previously declared in include/globalfunctions.php:3)

  at include/globalfunctions.php:3
      1▕ <?php
      2▕
  ➜   3▕ function get_global_sp_state()
      4▕ {
      5▕        static $global_promotion_state;
      6▕        $cacheKey = \App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY;
      7▕        if (is_null($global_promotion_state)) {
      8▕         $row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
      9▕             return \Nexus\Database\NexusDB::getOne('torrents_state', 1);

      +1 vendor frames

  2   [internal]:0
      Whoops\Run::handleShutdown()
```

So we should use `require_once` instead of `require` to avoid this issue.

Signed-off-by: Qi HU <github@spcsky.com>
2025-10-02 21:46:24 +08:00

66 lines
2.0 KiB
PHP

<?php
defined('LARAVEL_START') || define('LARAVEL_START', microtime(true));
defined('IN_NEXUS') || define('IN_NEXUS', false);
require_once dirname(__DIR__) . '/include/constants.php';
require_once dirname(__DIR__) . '/include/globalfunctions.php';
require_once dirname(__DIR__) . '/include/functions.php';
if (!RUNNING_IN_OCTANE) {
\Nexus\Nexus::boot();
}
$GLOBALS['hook'] = $hook = new \Nexus\Plugin\Hook();
$GLOBALS['plugin'] = $plugin = new \Nexus\Plugin\Plugin();
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;