Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
@@ -4,21 +4,30 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Core;
|
||||
|
||||
use App\Framework\Cache\Cache;
|
||||
use App\Framework\Cache\CacheInitializer;
|
||||
use App\Framework\Config\Configuration;
|
||||
use App\Framework\Config\EncryptedEnvLoader;
|
||||
use App\Framework\Config\Environment;
|
||||
use App\Framework\Config\EnvironmentType;
|
||||
use App\Framework\Config\SecretManager;
|
||||
use App\Framework\Config\TypedConfigInitializer;
|
||||
use App\Framework\Config\TypedConfiguration;
|
||||
use App\Framework\Console\ConsoleApplication;
|
||||
use App\Framework\Console\ConsoleOutput;
|
||||
use App\Framework\Context\ExecutionContext;
|
||||
use App\Framework\DI\DefaultContainer;
|
||||
use App\Framework\Core\Events\EventDispatcher;
|
||||
use App\Framework\Core\Events\EventDispatcherInterface;
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\DI\DefaultContainer;
|
||||
use App\Framework\Encryption\EncryptionFactory;
|
||||
use App\Framework\ErrorHandling\CliErrorHandler;
|
||||
use App\Framework\ErrorHandling\ErrorHandler;
|
||||
use App\Framework\Http\MiddlewareManager;
|
||||
use App\Framework\Http\MiddlewareManagerInterface;
|
||||
use App\Framework\Http\ResponseEmitter;
|
||||
use App\Framework\Http\ServerEnvironment;
|
||||
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
|
||||
use App\Framework\Performance\MemoryMonitor;
|
||||
use App\Framework\Performance\PerformanceCategory;
|
||||
use App\Framework\Performance\PerformanceMeter;
|
||||
use App\Framework\Random\RandomGenerator;
|
||||
|
||||
/**
|
||||
* Verantwortlich für die grundlegende Initialisierung der Anwendung
|
||||
@@ -30,34 +39,49 @@ final readonly class AppBootstrapper
|
||||
private ContainerBootstrapper $bootstrapper;
|
||||
|
||||
public function __construct(
|
||||
private string $basePath,
|
||||
private PerformanceMeter $meter,
|
||||
private array $config = [],
|
||||
){
|
||||
private string $basePath,
|
||||
private PerformanceCollectorInterface $collector,
|
||||
private MemoryMonitor $memoryMonitor,
|
||||
#private array $config = [],
|
||||
) {
|
||||
$this->container = new DefaultContainer();
|
||||
$this->bootstrapper = new ContainerBootstrapper($this->container);
|
||||
|
||||
// Initialize environment with encryption support
|
||||
$env = $this->initializeEnvironment();
|
||||
|
||||
$env = Environment::fromFile($this->basePath . '/.env');
|
||||
// Make Environment available throughout the application
|
||||
$this->container->instance(Environment::class, $env);
|
||||
|
||||
$this->container->instance(TypedConfiguration::class, new TypedConfigInitializer($env)($this->container));
|
||||
|
||||
|
||||
// ExecutionContext detection sollte das erste sein, das nach dem Instanzieren des containers passiert. noch bevor dem bootstrap des containers.
|
||||
$executionContext = ExecutionContext::detect();
|
||||
// ExecutionContext detection sollte das erste sein, das nach dem Instanziieren des containers passiert. noch bevor dem bootstrap des containers.
|
||||
$executionContext = ExecutionContext::detect($env);
|
||||
$this->container->instance(ExecutionContext::class, $executionContext);
|
||||
|
||||
error_log("AppBootstrapper: Context detected as {$executionContext->getType()->value}");
|
||||
error_log('AppBootstrapper: Context metadata: ' . json_encode($executionContext->getMetadata()));
|
||||
// Register MemoryMonitor as singleton
|
||||
$this->container->singleton(MemoryMonitor::class, $this->memoryMonitor);
|
||||
|
||||
// Only log context in development - production doesn't need this noise
|
||||
$envType = EnvironmentType::fromEnvironment($env);
|
||||
#error_log("AppBootstrapper: 🚀 Context detected as {$executionContext->getType()->value}");
|
||||
#error_log("AppBootstrapper: Debug - isProduction: " . ($envType->isProduction() ? 'true' : 'false'));
|
||||
}
|
||||
|
||||
public function bootstrapWeb(): Application
|
||||
public function bootstrapWeb(): ApplicationInterface
|
||||
{
|
||||
$this->bootstrap();
|
||||
$this->registerWebErrorHandler();
|
||||
$this->registerApplication();
|
||||
|
||||
return $this->container->get(Application::class);
|
||||
$mm = $this->container->get(MiddlewareManager::class);
|
||||
$this->container->instance(MiddlewareManagerInterface::class, $mm);
|
||||
|
||||
$ed = $this->container->get(EventDispatcher::class);
|
||||
$this->container->instance(EventDispatcherInterface::class, $ed);
|
||||
|
||||
return $this->container->get(ApplicationInterface::class);
|
||||
}
|
||||
|
||||
public function bootstrapConsole(): ConsoleApplication
|
||||
@@ -80,16 +104,31 @@ final readonly class AppBootstrapper
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function bootstrapWebSocket(): Container
|
||||
{
|
||||
$this->bootstrap();
|
||||
$this->registerCliErrorHandler();
|
||||
|
||||
$consoleOutput = new ConsoleOutput();
|
||||
$this->container->instance(ConsoleOutput::class, $consoleOutput);
|
||||
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
private function bootstrap(): void
|
||||
{
|
||||
$this->meter->startMeasure('bootstrap:start', PerformanceCategory::SYSTEM);
|
||||
$this->collector->startTiming('bootstrap', PerformanceCategory::SYSTEM);
|
||||
|
||||
$this->bootstrapper->bootstrap($this->basePath, $this->meter, $this->config);
|
||||
$this->bootstrapper->bootstrap($this->basePath, $this->collector);
|
||||
|
||||
$this->collector->endTiming('bootstrap');
|
||||
|
||||
// Initialize secrets management after container is bootstrapped
|
||||
$env = $this->container->get(Environment::class);
|
||||
$this->initializeSecretsManagement($env);
|
||||
|
||||
// ErrorHandler wird jetzt kontextabhängig registriert
|
||||
// $this->container->get(ErrorHandler::class)->register();
|
||||
|
||||
$this->meter->endMeasure('bootstrap:end');
|
||||
}
|
||||
|
||||
private function registerWebErrorHandler(): void
|
||||
@@ -103,18 +142,17 @@ final readonly class AppBootstrapper
|
||||
? $this->container->get(ConsoleOutput::class)
|
||||
: new ConsoleOutput();
|
||||
|
||||
$cliErrorHandler = new \App\Framework\ErrorHandling\CliErrorHandler($output);
|
||||
$cliErrorHandler = new CliErrorHandler($output);
|
||||
$cliErrorHandler->register();
|
||||
}
|
||||
|
||||
private function registerApplication(): void
|
||||
{
|
||||
$this->container->singleton(Application::class, function (Container $c) {
|
||||
$this->container->singleton(ApplicationInterface::class, function (Container $c) {
|
||||
return new Application(
|
||||
$c,
|
||||
$c->get(PathProvider::class),
|
||||
$c->get(ResponseEmitter::class),
|
||||
$c->get(Configuration::class)
|
||||
$c->get(TypedConfiguration::class)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -130,4 +168,64 @@ final readonly class AppBootstrapper
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize environment with encryption support
|
||||
*/
|
||||
private function initializeEnvironment(): Environment
|
||||
{
|
||||
// First, try to load basic environment to get encryption key
|
||||
$basicEnv = Environment::fromFile($this->basePath . '/.env');
|
||||
$encryptionKey = $basicEnv->get('ENCRYPTION_KEY');
|
||||
|
||||
// If we have an encryption key, use the encrypted loader
|
||||
if ($encryptionKey !== null) {
|
||||
try {
|
||||
// These dependencies will be resolved later through the container
|
||||
$randomGenerator = $this->container->get(RandomGenerator::class);
|
||||
$encryptionFactory = new EncryptionFactory($randomGenerator);
|
||||
$encryptedLoader = new EncryptedEnvLoader($encryptionFactory, $randomGenerator);
|
||||
|
||||
return $encryptedLoader->loadEnvironment($this->basePath, $encryptionKey);
|
||||
} catch (\Throwable $e) {
|
||||
// Fallback to basic environment if encryption fails
|
||||
error_log("Failed to load encrypted environment: " . $e->getMessage());
|
||||
|
||||
return $basicEnv;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to basic environment loading
|
||||
return $basicEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize secrets management after container is bootstrapped
|
||||
*/
|
||||
private function initializeSecretsManagement(Environment $env): void
|
||||
{
|
||||
$encryptionKey = $env->get('ENCRYPTION_KEY');
|
||||
|
||||
if ($encryptionKey === null) {
|
||||
return; // No secrets management without encryption key
|
||||
}
|
||||
|
||||
try {
|
||||
$randomGenerator = $this->container->get(RandomGenerator::class);
|
||||
$serverEnvironment = $this->container->get(ServerEnvironment::class);
|
||||
$encryptionFactory = new EncryptionFactory($randomGenerator);
|
||||
$encryption = $encryptionFactory->createBest($encryptionKey);
|
||||
|
||||
$secretManager = new SecretManager(
|
||||
$env,
|
||||
$encryption,
|
||||
$serverEnvironment,
|
||||
$randomGenerator
|
||||
);
|
||||
|
||||
$this->container->instance(SecretManager::class, $secretManager);
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Failed to initialize secrets management: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user