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 Jan 4, 2024
2 parents efaea0f + 5b188ce commit 9cfae94
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 345 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/config/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ AUTH_SALT='generateme'
SECURE_AUTH_SALT='generateme'
LOGGED_IN_SALT='generateme'
NONCE_SALT='generateme'

ACORN_ENABLE_EXPERIMENTAL_ROUTER='true'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Acorn is an open source project and completely free to use. If you've benefited from our projects and would like to support our future endeavors, please consider [sponsoring Roots](https://github.com/sponsors/roots).

<div align="center">
<a href="https://k-m.com/"><img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="120" height="90"></a> <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="120" height="90"></a> <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="120" height="90"></a> <a href="https://worksitesafety.ca/careers/"><img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="120" height="90"></a> <a href="https://www.freave.com/"><img src="https://cdn.roots.io/app/uploads/freave.svg" alt="Freave" width="120" height="90"></a>
<a href="https://k-m.com/"><img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="120" height="90"></a> <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="120" height="90"></a> <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="120" height="90"></a> <a href="https://worksitesafety.ca/careers/"><img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="120" height="90"></a> <a href="https://www.copiadigital.com/"><img src="https://cdn.roots.io/app/uploads/copia-digital.svg" alt="Copia Digital" width="120" height="90"></a> <a href="https://www.freave.com/"><img src="https://cdn.roots.io/app/uploads/freave.svg" alt="Freave" width="120" height="90"></a>
</div>

## Overview
Expand All @@ -54,7 +54,7 @@ Acorn is a framework for integrating Laravel within WordPress.
| illuminate/filesystem | 🟢 | |
| illuminate/http | 🟢 | |
| illuminate/log | 🟢 | |
| illuminate/routing | 🟡 | Requires `ACORN_ENABLE_EXPERIMENTAL_ROUTER` env var |
| illuminate/routing | 🟢 | |
| illuminate/support | 🟢 | |
| illuminate/view | 🟢 | |

Expand Down
19 changes: 11 additions & 8 deletions bin/acorn
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
<?php

(static function () {
if (! is_file($autoload_path = dirname(__DIR__, 4) . '/vendor/autoload.php')) {
$autoload_path = dirname(__DIR__) . '/vendor/autoload.php';
if (! is_file($autoloadPath = dirname(__DIR__, 4) . '/vendor/autoload.php')) {
$autoloadPath = dirname(__DIR__) . '/vendor/autoload.php';
}

if (filter_input(INPUT_ENV, 'APPLICATION_PATH')) {
$autoload_path = filter_input(INPUT_ENV, 'APPLICATION_PATH') . '/vendor/autoload.php';
$autoloadPath = filter_input(INPUT_ENV, 'APPLICATION_PATH') . '/vendor/autoload.php';
}
require_once $autoload_path;

$composer_path = (new Roots\Acorn\Filesystem\Filesystem)->closest(dirname($autoload_path, 2), 'composer.json');
require_once $autoloadPath;

$composerPath = (new Roots\Acorn\Filesystem\Filesystem)->closest(dirname($autoloadPath, 2), 'composer.json');

$root_path = dirname($composer_path);
$rootPath = dirname($composerPath);

$composer = json_decode(file_get_contents($composer_path), true);
$composer = json_decode(file_get_contents($composerPath), true);

define('WP_USE_THEMES', false);
require_once "{$root_path}/{$composer['extra']['wordpress-install-dir']}/wp-blog-header.php";

require_once "{$rootPath}/{$composer['extra']['wordpress-install-dir']}/wp-blog-header.php";

Roots\Acorn\Bootloader::getInstance()->boot();
})();
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"illuminate/support": "^10.33",
"illuminate/view": "^10.33",
"laravel/prompts": "^0.1.7",
"laravel/serializable-closure": "^1.3",
"league/flysystem": "^3.8",
"ramsey/uuid": "^4.7",
"roots/support": "^1.0",
Expand Down
21 changes: 7 additions & 14 deletions src/Roots/Acorn/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Foundation\PackageManifest as FoundationPackageManifest;
use Illuminate\Foundation\ProviderRepository;
use Illuminate\Support\Collection;
use Illuminate\Support\Env;
use Illuminate\Support\ServiceProvider;
use Roots\Acorn\Exceptions\SkipProviderException;
use Roots\Acorn\Filesystem\Filesystem;
Expand Down Expand Up @@ -84,7 +83,7 @@ protected function registerGlobalHelpers()
*/
public function usePaths(array $paths)
{
$supported_paths = [
$supportedPaths = [
'app' => 'appPath',
'lang' => 'langPath',
'config' => 'configPath',
Expand All @@ -95,14 +94,14 @@ public function usePaths(array $paths)
'bootstrap' => 'bootstrapPath',
];

foreach ($paths as $path_type => $path) {
foreach ($paths as $pathType => $path) {
$path = rtrim($path, '\\/');

if (! isset($supported_paths[$path_type])) {
throw new Exception("The {$path_type} path type is not supported.");
if (! isset($supportedPaths[$pathType])) {
throw new Exception("The {$pathType} path type is not supported.");
}

$this->{$supported_paths[$path_type]} = $path;
$this->{$supportedPaths[$pathType]} = $path;
}

$this->bindPathsInContainer();
Expand Down Expand Up @@ -329,11 +328,11 @@ public function getNamespace()
return $this->namespace;
}

$composer = json_decode(file_get_contents($composer_path = $this->getAppComposer()), true);
$composer = json_decode(file_get_contents($composerPath = $this->getAppComposer()), true);

foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
foreach ((array) $path as $pathChoice) {
if (realpath($this->path()) === realpath(dirname($composer_path).DIRECTORY_SEPARATOR.$pathChoice)) {
if (realpath($this->path()) === realpath(dirname($composerPath).DIRECTORY_SEPARATOR.$pathChoice)) {
return $this->namespace = $namespace;
}
}
Expand Down Expand Up @@ -378,10 +377,4 @@ public function version()
{
return 'Acorn '.static::VERSION.' (Laravel '.parent::VERSION.')';
}

public static function isExperimentalRouterEnabled()
{
return Env::get('ACORN_ENABLE_EXPERIMENTAL_ROUTER', false)
|| Env::get('ACORN_ENABLE_EXPIRIMENTAL_ROUTER', false);
}
}
24 changes: 12 additions & 12 deletions src/Roots/Acorn/Assets/Asset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@
class Asset implements AssetContract
{
/**
* Local path
* The local asset path.
*
* @var string
*/
protected $path;

/**
* Remote URI
* The remote asset URI.
*
* @var string
*/
protected $uri;

/**
* MIME Content Type
* The asset MIME content type.
*
* @var string
*/
protected $type;

/**
* Base64-encoded contents
* The asset base64-encoded contents.
*
* @var string
*/
protected $base64;

/**
* Data URL of asset.
* The asset data URL.
*
* @var string
*/
Expand Down Expand Up @@ -86,17 +86,17 @@ public function contents(): string
/**
* Get the relative path to the asset.
*
* @param string $base_path Base path to use for relative path.
* @param string $basePath Base path to use for relative path.
*/
public function relativePath(string $base_path): string
public function relativePath(string $basePath): string
{
$base_path = rtrim($base_path, '/\\').'/';
$basePath = rtrim($basePath, '/\\').'/';

return (new Filesystem())->getRelativePath($base_path, $this->path());
return (new Filesystem())->getRelativePath($basePath, $this->path());
}

/**
* Base64-encoded contents
* Get the base64-encoded contents of the asset.
*
* @return string
*/
Expand Down Expand Up @@ -138,7 +138,7 @@ public function dataUri(?string $mediatype = null): string
}

/**
* Get the MIME content type
* Get the MIME content type.
*
* @return string|false
*/
Expand All @@ -152,7 +152,7 @@ public function contentType()
}

/**
* Get the MIME content type
* Get the MIME content type.
*
* @return string|false
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Roots/Acorn/Assets/AssetsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function boot()
}
}

/**
* Get the default manifest.
*
* @return string
*/
protected function getDefaultManifest()
{
return $this->app['config']['assets.default'];
Expand Down
8 changes: 4 additions & 4 deletions src/Roots/Acorn/Assets/Concerns/Enqueuable.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function enqueueCss(string $media = 'all', array $dependencies = [])
*/
public function enqueueJs(bool|array $args = true, array $dependencies = [])
{
$this->js(function ($handle, $src, $bundle_dependencies) use (&$dependencies, $args) {
$this->mergeDependencies($dependencies, $bundle_dependencies);
$this->js(function ($handle, $src, $bundleDependencies) use (&$dependencies, $args) {
$this->mergeDependencies($dependencies, $bundleDependencies);

wp_enqueue_script($handle, $src, $dependencies, null, $args);

Expand Down Expand Up @@ -188,9 +188,9 @@ public function localize($name, $object)
*
* @return void
*/
protected function mergeDependencies(array &$dependencies, array ...$more_dependencies)
protected function mergeDependencies(array &$dependencies, array ...$moreDependencies)
{
$dependencies = array_unique(array_merge($dependencies, ...$more_dependencies));
$dependencies = array_unique(array_merge($dependencies, ...$moreDependencies));
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Roots/Acorn/Assets/Contracts/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public function exists(): bool;
*/
public function contents();

/**
* Get the relative path to the asset.
*
* @param string $base_path Base path to use for relative path.
*/
public function relativePath(string $base_path): string;

/**
* Get data URL of asset.
*
Expand Down
30 changes: 27 additions & 3 deletions src/Roots/Acorn/Assets/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,37 @@

class Manifest implements ManifestContract
{
/**
* The manifest assets.
*
* @var array
*/
protected $assets;

/**
* The manifest bundles.
*
* @var array
*/
protected $bundles;

/**
* The manifest path.
*
* @var string
*/
protected $path;

/**
* The manifest URI.
*
* @var string
*/
protected $uri;

/**
* Create a new manifest instance.
*/
public function __construct(string $path, string $uri, array $assets = [], ?array $bundles = null)
{
$this->path = $path;
Expand All @@ -36,9 +59,10 @@ public function __construct(string $path, string $uri, array $assets = [], ?arra
public function asset($key): AssetContract
{
$key = $this->normalizeRelativePath($key);
$relative_path = $this->assets[$key] ?? $key;
$path = Str::before("{$this->path}/{$relative_path}", '?');
$uri = "{$this->uri}/{$relative_path}";
$relativePath = $this->assets[$key] ?? $key;

$path = Str::before("{$this->path}/{$relativePath}", '?');
$uri = "{$this->uri}/{$relativePath}";

return AssetFactory::create($path, $uri);
}
Expand Down
19 changes: 12 additions & 7 deletions src/Roots/Acorn/Assets/Middleware/RootsBudMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
class RootsBudMiddleware
{
/**
* Dev server URI
* The Bud dev server origin header.
*
* @var string
*/
protected $dev_origin;
protected $devOrigin;

public function __construct(?string $dev_origin = null)
/**
* Create a new Bud middleware instance.
*
* @return void
*/
public function __construct(?string $devOrigin = null)
{
$this->dev_origin = $dev_origin;
$this->devOrigin = $devOrigin;
}

/**
Expand Down Expand Up @@ -44,15 +49,15 @@ protected function getBudDevUri(string $path): ?string
return null;
}

if (! $dev_origin_header = $this->getDevOriginHeader()) {
if (! $devOriginHeader = $this->getDevOriginHeader()) {
return null;
}

if (! $dev = optional(json_decode(file_get_contents($path)))->dev) {
return null;
}

if (strstr($dev_origin_header, $dev->hostname) === false) {
if (strstr($devOriginHeader, $dev->hostname) === false) {
return null;
}

Expand All @@ -66,7 +71,7 @@ protected function getBudDevUri(string $path): ?string
*/
protected function getDevOriginHeader()
{
return $this->dev_origin
return $this->devOrigin
?: filter_input(INPUT_ENV, 'HTTP_X_BUD_DEV_ORIGIN', FILTER_SANITIZE_URL)
?: filter_input(INPUT_SERVER, 'HTTP_X_BUD_DEV_ORIGIN', FILTER_SANITIZE_URL);
}
Expand Down
Loading

0 comments on commit 9cfae94

Please sign in to comment.