Skip to content
Merged
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
40 changes: 31 additions & 9 deletions src/frameworks/cakephp/http_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,18 @@ function () use ($projectRoot, $ddlessDirectory, &$__ddless_cake_error) {
// CLI mode (DDLess direct request): manual bootstrap, capture response, snapshot.
// ═══════════════════════════════════════════════════════════════════════════════

$breakpoints = ddless_read_breakpoints($ddlessDirectory);
$executionStartedAt = microtime(true);

// Register stream wrapper BEFORE autoload — same order as proxy mode.
// The wrapper must be active when Composer's autoloader is set up so that
// all subsequent include/require calls go through it.
if (getenv('DDLESS_DEBUG_MODE') === 'true') {
if (function_exists('ddless_register_stream_wrapper')) {
ddless_register_stream_wrapper();
}
}

require_once $projectRoot . '/vendor/autoload.php';

$bootstrapFile = $projectRoot . '/config/bootstrap.php';
Expand All @@ -544,8 +556,6 @@ function () use ($projectRoot, $ddlessDirectory, &$__ddless_cake_error) {
exit(1);
}

$breakpoints = ddless_read_breakpoints($ddlessDirectory);
$executionStartedAt = microtime(true);
$logDir = defined('LOGS') ? LOGS : $projectRoot . DIRECTORY_SEPARATOR . 'logs';

$phpWrapperReplaced = false;
Expand All @@ -559,12 +569,10 @@ function () use ($projectRoot, $ddlessDirectory, &$__ddless_cake_error) {
}
}

if (getenv('DDLESS_DEBUG_MODE') === 'true') {
$debugModule = dirname(__DIR__, 2) . '/debug.php';
if (file_exists($debugModule)) {
require_once $debugModule;
if (function_exists('ddless_register_stream_wrapper')) {
ddless_register_stream_wrapper();
if (getenv('DDLESS_DEBUG_MODE') === 'true' && !empty($GLOBALS['__DDLESS_INSTRUMENTED_CODE__'])) {
foreach (array_keys($GLOBALS['__DDLESS_INSTRUMENTED_CODE__']) as $instrumentedPath) {
if (is_file($instrumentedPath) && str_ends_with($instrumentedPath, '.php')) {
include_once $instrumentedPath;
}
}
}
Expand All @@ -576,6 +584,21 @@ function () use ($projectRoot, $ddlessDirectory, &$__ddless_cake_error) {
$app->bootstrap();
$app->pluginBootstrap();

// Server::run() always calls bootstrap() internally, which would re-load
// plugins (DebugKit) and crash. This subclass guards against double bootstrap.
$server = new class($app) extends \Cake\Http\Server {
private bool $__bootstrapped = false;
protected function bootstrap(): void {
if ($this->__bootstrapped) return;
parent::bootstrap();
$this->__bootstrapped = true;
}
public function skipBootstrap(): void {
$this->__bootstrapped = true;
}
};
$server->skipBootstrap();

$request = \Cake\Http\ServerRequestFactory::fromGlobals();

if (!empty($_FILES) && class_exists('Laminas\Diactoros\UploadedFile')) {
Expand Down Expand Up @@ -612,7 +635,6 @@ function () use ($projectRoot, $ddlessDirectory, &$__ddless_cake_error) {
}
}

$server = new \Cake\Http\Server($app);
$response = $server->run($request);

$statusCode = $response->getStatusCode();
Expand Down