Skip to content

Commit

Permalink
Merge branch 'roots:main' into fse
Browse files Browse the repository at this point in the history
  • Loading branch information
dsturm authored Feb 6, 2024
2 parents fa4d942 + d049493 commit 4ec89da
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
18 changes: 15 additions & 3 deletions .devcontainer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,30 @@ if [ -d "web" ]; then
fi
fi

# use `content` instead of `app` for wp-content
if [ -d "public/app" ]; then
mv public/app public/content
sed -i 's/public\/app/public\/content/g' composer.json

if [ -f 'config/application.php' ]; then
sed -i 's/\/app/\/content/g' config/application.php
elif [ -f 'bedrock/application.php' ]; then
sed -i 's/\/app/\/content/g' bedrock/application.php
fi
fi

cd /roots/app

# Install Composer dependencies
composer -d /roots/app install --no-progress --optimize-autoloader --prefer-dist --no-interaction

# Link the workspace folder
if cat "${WORKSPACE_FOLDER}/composer.json" | jq '.type' | grep -q wordpress-theme; then
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/app/themes/$(basename ${WORKSPACE_FOLDER})"
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/content/themes/$(basename ${WORKSPACE_FOLDER})"
elif cat "${WORKSPACE_FOLDER}/composer.json" | jq '.type' | grep -q wordpress-plugin; then
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/app/plugins/$(basename ${WORKSPACE_FOLDER})"
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/content/plugins/$(basename ${WORKSPACE_FOLDER})"
elif cat "${WORKSPACE_FOLDER}/composer.json" | jq '.type' | grep -q wordpress-muplugin; then
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/app/mu-plugins/$(basename ${WORKSPACE_FOLDER})"
ln -fs "${WORKSPACE_FOLDER}" "/roots/app/public/content/mu-plugins/$(basename ${WORKSPACE_FOLDER})"
else
cat /roots/app/composer.json | jq ".repositories += [{ type: \"path\", url: \"${WORKSPACE_FOLDER}\" }]" > /roots/app/composer.tmp \
&& rm /roots/app/composer.json \
Expand Down
51 changes: 35 additions & 16 deletions src/Roots/Acorn/Bootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,19 @@ protected function bootHttp(ApplicationContract $app)
/** @var \Illuminate\Routing\Route $route */
$route = $app->make('router')->getRoutes()->match($request);

/** @var array $config */
$config = $app->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']);
if ($route->getName() !== 'wordpress_request') {
$this->registerRequestHandler($kernel, $request, $route);
} elseif (env('ACORN_ENABLE_EXPERIMENTAL_WORDPRESS_REQUEST_HANDLER', false)) {
$this->registerWordPressRequestHandler($kernel, $request, $route, $app->config->get('router.wordpress', ['web' => 'web', 'api' => 'api']));
}

$this->registerRequestHandler($kernel, $request, $route, $config);
add_filter('do_parse_request', function ($doParse, \WP $wp, $extraQueryVars) use ($route) {
if ($route->getName() === 'wordpress_request') {
return $doParse;
}

return apply_filters('acorn/router/do_parse_request', $doParse, $wp, $extraQueryVars);
}, 100, 3);
}

/**
Expand All @@ -228,7 +237,7 @@ protected function bootHttp(ApplicationContract $app)
protected function registerWordPressRoute(ApplicationContract $app)
{
$app->make('router')
->any('{any?}', fn () => tap(response(''), function (Response $response) {
->any('{any?}', fn () => tap(response(''), function (Response $response) use ($app) {
foreach (headers_list() as $header) {
[$header, $value] = explode(': ', $header, 2);
if (! headers_sent()) {
Expand All @@ -237,6 +246,10 @@ protected function registerWordPressRoute(ApplicationContract $app)
$response->header($header, $value);
}

if ($app->hasDebugModeEnabled()) {
$response->header('X-Powered-By', $app->version());
}

$content = '';

$levels = ob_get_level();
Expand All @@ -256,6 +269,22 @@ protected function registerWordPressRoute(ApplicationContract $app)
* @return void
*/
protected function registerRequestHandler(
\Illuminate\Contracts\Http\Kernel $kernel,
\Illuminate\Http\Request $request,
?\Illuminate\Routing\Route $route
) {
add_filter('do_parse_request', function ($doParse, \WP $wp, $extraQueryVars) use ($route) {
if (! $route) {
return $doParse;
}

return apply_filters('acorn/router/do_parse_request', $doParse, $wp, $extraQueryVars);
}, 100, 3);

add_action('parse_request', fn () => $this->handleRequest($kernel, $request));
}

protected function registerWordPressRequestHandler(
\Illuminate\Contracts\Http\Kernel $kernel,
\Illuminate\Http\Request $request,
?\Illuminate\Routing\Route $route,
Expand All @@ -270,18 +299,8 @@ protected function registerRequestHandler(
return; // Let WordPress handle these requests
}

add_filter('do_parse_request', function ($doParse, \WP $wp, $extraQueryVars) use ($route) {
if (! $route) {
return $doParse;
}

return apply_filters('acorn/router/do_parse_request', $doParse, $wp, $extraQueryVars);
}, 100, 3);

if ($route->getName() !== 'wordpress_request') {
add_action('parse_request', fn () => $this->handleRequest($kernel, $request));

return;
if (redirect_canonical(null, false)) {
return; // Let WordPress handle these requests
}

$route->middleware(preg_match('/^wp-json(\/.*)?/', $request->path()) ? $config['api'] : $config['web']);
Expand Down
2 changes: 2 additions & 0 deletions src/Roots/Acorn/DefaultProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function __construct(?array $providers = null)
$this->providers = Collection::make($this->providers)
->merge($this->acornProviders)
->filter(fn ($provider) => ! str_contains($provider, 'Illuminate\\Foundation\\'))
->push('Illuminate\\Foundation\\Providers\\ComposerServiceProvider')
->push('Illuminate\\Database\\MigrationServiceProvider')
->all();
}
}
1 change: 0 additions & 1 deletion src/Roots/Acorn/Providers/AcornServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AcornServiceProvider extends ServiceProvider
* @var string[]
*/
protected $providerConfigs = [
\Fruitcake\Cors\CorsServiceProvider::class => 'cors',
\Illuminate\Auth\AuthServiceProvider::class => 'auth',
\Illuminate\Broadcasting\BroadcastServiceProvider::class => 'broadcasting',
\Illuminate\Cache\CacheServiceProvider::class => 'cache',
Expand Down

0 comments on commit 4ec89da

Please sign in to comment.