From 670abe82a44ae3f2371b876c5f4458ef8b09c2fb Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 11 Dec 2023 05:34:03 -0600 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=8E=A8=20Change=20variables/propertie?= =?UTF-8?q?s=20from=20snake=5Fcase=20to=20camelCase=20(#321)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/acorn | 19 ++++++----- composer.json | 3 +- src/Roots/Acorn/Application.php | 14 ++++---- src/Roots/Acorn/Assets/Asset/Asset.php | 24 ++++++------- .../Acorn/Assets/AssetsServiceProvider.php | 5 +++ .../Acorn/Assets/Concerns/Enqueuable.php | 8 ++--- src/Roots/Acorn/Assets/Manifest.php | 30 ++++++++++++++-- .../Assets/Middleware/RootsBudMiddleware.php | 19 +++++++---- src/Roots/Acorn/Bootloader.php | 14 ++++---- src/Roots/Acorn/Bootstrap/RegisterConsole.php | 4 +-- .../Console/Commands/AcornInitCommand.php | 34 +++++++++++++------ .../Console/Commands/VendorPublishCommand.php | 4 +-- src/Roots/Acorn/Filesystem/Filesystem.php | 4 +-- .../Acorn/Providers/RouteServiceProvider.php | 8 ++--- .../Acorn/Sage/Concerns/FiltersTemplates.php | 28 +++++++-------- .../View/Composers/Concerns/AcfFields.php | 6 ++-- tests/Application/BootloaderTest.php | 18 +++++----- 17 files changed, 147 insertions(+), 95 deletions(-) diff --git a/bin/acorn b/bin/acorn index 2f9c1ac7..29563b64 100755 --- a/bin/acorn +++ b/bin/acorn @@ -2,22 +2,25 @@ 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(); })(); diff --git a/composer.json b/composer.json index c6d4502f..e492f27b 100644 --- a/composer.json +++ b/composer.json @@ -82,7 +82,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "pestphp/pest-plugin": true + "pestphp/pest-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true } }, "minimum-stability": "dev", diff --git a/src/Roots/Acorn/Application.php b/src/Roots/Acorn/Application.php index bdad862c..68006172 100644 --- a/src/Roots/Acorn/Application.php +++ b/src/Roots/Acorn/Application.php @@ -84,7 +84,7 @@ protected function registerGlobalHelpers() */ public function usePaths(array $paths) { - $supported_paths = [ + $supportedPaths = [ 'app' => 'appPath', 'lang' => 'langPath', 'config' => 'configPath', @@ -95,14 +95,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(); @@ -329,11 +329,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; } } diff --git a/src/Roots/Acorn/Assets/Asset/Asset.php b/src/Roots/Acorn/Assets/Asset/Asset.php index 6ccecc62..3d3f2339 100644 --- a/src/Roots/Acorn/Assets/Asset/Asset.php +++ b/src/Roots/Acorn/Assets/Asset/Asset.php @@ -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 */ @@ -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 */ @@ -138,7 +138,7 @@ public function dataUri(?string $mediatype = null): string } /** - * Get the MIME content type + * Get the MIME content type. * * @return string|false */ @@ -152,7 +152,7 @@ public function contentType() } /** - * Get the MIME content type + * Get the MIME content type. * * @return string|false */ diff --git a/src/Roots/Acorn/Assets/AssetsServiceProvider.php b/src/Roots/Acorn/Assets/AssetsServiceProvider.php index eebcb26f..43313c76 100644 --- a/src/Roots/Acorn/Assets/AssetsServiceProvider.php +++ b/src/Roots/Acorn/Assets/AssetsServiceProvider.php @@ -39,6 +39,11 @@ public function boot() } } + /** + * Get the default manifest. + * + * @return string + */ protected function getDefaultManifest() { return $this->app['config']['assets.default']; diff --git a/src/Roots/Acorn/Assets/Concerns/Enqueuable.php b/src/Roots/Acorn/Assets/Concerns/Enqueuable.php index 79f42ed7..3731d085 100644 --- a/src/Roots/Acorn/Assets/Concerns/Enqueuable.php +++ b/src/Roots/Acorn/Assets/Concerns/Enqueuable.php @@ -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); @@ -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)); } /** diff --git a/src/Roots/Acorn/Assets/Manifest.php b/src/Roots/Acorn/Assets/Manifest.php index 41cf8f42..cd516861 100644 --- a/src/Roots/Acorn/Assets/Manifest.php +++ b/src/Roots/Acorn/Assets/Manifest.php @@ -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; @@ -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); } diff --git a/src/Roots/Acorn/Assets/Middleware/RootsBudMiddleware.php b/src/Roots/Acorn/Assets/Middleware/RootsBudMiddleware.php index f17e6938..bf28f557 100644 --- a/src/Roots/Acorn/Assets/Middleware/RootsBudMiddleware.php +++ b/src/Roots/Acorn/Assets/Middleware/RootsBudMiddleware.php @@ -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; } /** @@ -44,7 +49,7 @@ protected function getBudDevUri(string $path): ?string return null; } - if (! $dev_origin_header = $this->getDevOriginHeader()) { + if (! $devOriginHeader = $this->getDevOriginHeader()) { return null; } @@ -52,7 +57,7 @@ protected function getBudDevUri(string $path): ?string return null; } - if (strstr($dev_origin_header, $dev->hostname) === false) { + if (strstr($devOriginHeader, $dev->hostname) === false) { return null; } @@ -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); } diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index ca26ba7e..f33315a1 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -127,7 +127,7 @@ public function boot($callback = null) } /** - * Enable $_SERVER[HTTPS] in a console environment. + * Enable `$_SERVER[HTTPS]` in a console environment. * * @return void */ @@ -168,12 +168,12 @@ protected function bootWpCli(ApplicationContract $app) $kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); - \WP_CLI::add_command('acorn', function ($args, $assoc_args) use ($kernel) { + \WP_CLI::add_command('acorn', function ($args, $assocArgs) use ($kernel) { $kernel->commands(); $command = implode(' ', $args); - foreach ($assoc_args as $key => $value) { + foreach ($assocArgs as $key => $value) { if ($key === 'interaction' && $value === false) { $command .= ' --no-interaction'; @@ -225,7 +225,7 @@ protected function bootHttp(ApplicationContract $app) add_filter( 'do_parse_request', - fn ($do_parse, \WP $wp, $extra_query_vars) => apply_filters('acorn/router/do_parse_request', $do_parse, $wp, $extra_query_vars), + fn ($doParse, \WP $wp, $extraQueryVars) => apply_filters('acorn/router/do_parse_request', $doParse, $wp, $extraQueryVars), 100, 3 ); @@ -305,11 +305,11 @@ protected function basePath(): string defined('ACORN_BASEPATH') => constant('ACORN_BASEPATH'), - is_file($composer_path = get_theme_file_path('composer.json')) => dirname($composer_path), + is_file($composerPath = get_theme_file_path('composer.json')) => dirname($composerPath), - is_dir($app_path = get_theme_file_path('app')) => dirname($app_path), + is_dir($appPath = get_theme_file_path('app')) => dirname($appPath), - is_file($vendor_path = $this->files->closest(dirname(__DIR__, 4), 'composer.json')) => dirname($vendor_path), + is_file($vendorPath = $this->files->closest(dirname(__DIR__, 4), 'composer.json')) => dirname($vendorPath), default => dirname(__DIR__, 3) }; diff --git a/src/Roots/Acorn/Bootstrap/RegisterConsole.php b/src/Roots/Acorn/Bootstrap/RegisterConsole.php index e8c20141..ac20763e 100644 --- a/src/Roots/Acorn/Bootstrap/RegisterConsole.php +++ b/src/Roots/Acorn/Bootstrap/RegisterConsole.php @@ -30,7 +30,7 @@ public function bootstrap(Application $app) return; } - WP_CLI::add_command('acorn', function ($args, $assoc_args) { + WP_CLI::add_command('acorn', function ($args, $assocArgs) { /** @var Kernel */ $kernel = $this->app->make(Kernel::class); @@ -38,7 +38,7 @@ public function bootstrap(Application $app) $command = implode(' ', $args); - foreach ($assoc_args as $key => $value) { + foreach ($assocArgs as $key => $value) { $command .= " {$this->formatOption($key, $value)}"; } diff --git a/src/Roots/Acorn/Console/Commands/AcornInitCommand.php b/src/Roots/Acorn/Console/Commands/AcornInitCommand.php index 91b60ec7..366c169f 100644 --- a/src/Roots/Acorn/Console/Commands/AcornInitCommand.php +++ b/src/Roots/Acorn/Console/Commands/AcornInitCommand.php @@ -68,7 +68,7 @@ class AcornInitCommand extends Command * * @var string */ - protected $base_path; + protected $basePath; /** * Create a new command instance. @@ -84,16 +84,23 @@ public function __construct(Filesystem $files, Application $app) $this->files = $files; } + /** + * Execute the console command. + * + * @return void + * + * @throws \Exception + */ public function handle() { - $this->base_path = realpath($this->option('base') ?: $this->app->basePath()); + $this->basePath = realpath($this->option('base') ?: $this->app->basePath()); - if (! is_writable($this->base_path)) { - throw new Exception("The {$this->base_path} directory must be present and writable."); + if (! is_writable($this->basePath)) { + throw new Exception("The {$this->basePath} directory must be present and writable."); } - if ($this->base_path === dirname(__DIR__, 5)) { - throw new Exception("The {$this->base_path} directory is invalid. Specify an alternative using --base option."); + if ($this->basePath === dirname(__DIR__, 5)) { + throw new Exception("The {$this->basePath} directory is invalid. Specify an alternative using --base option."); } $paths = array_map('strtolower', array_intersect( @@ -103,7 +110,7 @@ public function handle() foreach ($paths as $key) { if ($this->initPath($key, $path = $this->paths[$key])) { - $this->line("Initialized [{$this->base_path}/{$path}]"); + $this->line("Initialized [{$this->basePath}/{$path}]"); } } } @@ -118,6 +125,13 @@ protected function defaultPaths() return $this->defaults; } + /** + * Initialize the given path. + * + * @param string $key + * @param string $path + * @return bool + */ protected function initPath($key, $path) { if (! $this->createPath($path)) { @@ -143,12 +157,12 @@ protected function initPath($key, $path) */ protected function createPath($path) { - $this->files->ensureDirectoryExists("{$this->base_path}/{$path}", 0755, true); + $this->files->ensureDirectoryExists("{$this->basePath}/{$path}", 0755, true); if ($this->files->isDirectory($from = __DIR__."/stubs/paths/{$path}")) { - return $this->files->copyDirectory($from, "{$this->base_path}/{$path}"); + return $this->files->copyDirectory($from, "{$this->basePath}/{$path}"); } - return $this->files->isDirectory("{$this->base_path}/{$path}"); + return $this->files->isDirectory("{$this->basePath}/{$path}"); } } diff --git a/src/Roots/Acorn/Console/Commands/VendorPublishCommand.php b/src/Roots/Acorn/Console/Commands/VendorPublishCommand.php index d4f0dc2a..2397fc74 100644 --- a/src/Roots/Acorn/Console/Commands/VendorPublishCommand.php +++ b/src/Roots/Acorn/Console/Commands/VendorPublishCommand.php @@ -16,8 +16,8 @@ class VendorPublishCommand extends FoundationVendorPublishCommand */ protected function publishItem($from, $to) { - if (Str::startsWith($to, $vendor_path = dirname(__DIR__, 5))) { - $to = str_replace($vendor_path, $this->getLaravel()->basePath(), $to); + if (Str::startsWith($to, $vendorPath = dirname(__DIR__, 5))) { + $to = str_replace($vendorPath, $this->getLaravel()->basePath(), $to); $this->callAcornInit($from, $to); } diff --git a/src/Roots/Acorn/Filesystem/Filesystem.php b/src/Roots/Acorn/Filesystem/Filesystem.php index b5a722db..1874942f 100644 --- a/src/Roots/Acorn/Filesystem/Filesystem.php +++ b/src/Roots/Acorn/Filesystem/Filesystem.php @@ -30,8 +30,8 @@ public function closest($path, $file) $currentDirectory = $path; while ($this->isReadable($currentDirectory)) { - if ($this->isFile($file_path = $currentDirectory.DIRECTORY_SEPARATOR.$file)) { - return $file_path; + if ($this->isFile($filePath = $currentDirectory.DIRECTORY_SEPARATOR.$file)) { + return $filePath; } $parentDirectory = $this->dirname($currentDirectory); diff --git a/src/Roots/Acorn/Providers/RouteServiceProvider.php b/src/Roots/Acorn/Providers/RouteServiceProvider.php index a5413044..f7c12962 100644 --- a/src/Roots/Acorn/Providers/RouteServiceProvider.php +++ b/src/Roots/Acorn/Providers/RouteServiceProvider.php @@ -29,15 +29,15 @@ public function boot() $this->configureRateLimiting(); $this->routes(function () { - if (is_file($api_routes = base_path('routes/api.php'))) { + if (is_file($api = base_path('routes/api.php'))) { Route::middleware('api') ->prefix('api') - ->group($api_routes); + ->group($api); } - if (is_file($web_routes = base_path('routes/web.php'))) { + if (is_file($web = base_path('routes/web.php'))) { Route::middleware('web') - ->group($web_routes); + ->group($web); } }); } diff --git a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php index 5ae2667b..d98e7a02 100644 --- a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php +++ b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php @@ -54,10 +54,10 @@ public function filterTemplateInclude($file) * * @return string[] List of theme templates */ - public function filterThemeTemplates($_templates, $_theme, $_post, $post_type) + public function filterThemeTemplates($templates, $theme, $post, $postType) { - return collect($_templates) - ->merge($this->getTemplates($post_type, $_theme->load_textdomain() ? $_theme->get('TextDomain') : '')) + return collect($templates) + ->merge($this->getTemplates($postType, $theme->load_textdomain() ? $theme->get('TextDomain') : '')) ->unique() ->toArray(); } @@ -70,33 +70,33 @@ public function filterThemeTemplates($_templates, $_theme, $_post, $post_type) * @see \WP_Theme::get_post_templates() * @link https://github.com/WordPress/WordPress/blob/5.8.1/wp-includes/class-wp-theme.php#L1203-L1221 * - * @param string $post_type - * @param string $text_domain + * @param string $postType + * @param string $textDomain * @return string[] */ - protected function getTemplates($post_type = '', $text_domain = '') + protected function getTemplates($postType = '', $textDomain = '') { if ($templates = wp_cache_get('acorn/post_templates', 'themes')) { - return $templates[$post_type] ?? []; + return $templates[$postType] ?? []; } $templates = []; foreach (array_reverse($this->fileFinder->getPaths()) as $path) { foreach ( - array_filter($this->files->allFiles($path), fn ($file) => $file->getExtension() === 'php') as $full_path + array_filter($this->files->allFiles($path), fn ($file) => $file->getExtension() === 'php') as $fullPath ) { - if (! preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) { + if (! preg_match('|Template Name:(.*)$|mi', file_get_contents($fullPath), $header)) { continue; } $types = ['page']; - if (preg_match('|Template Post Type:(.*)$|mi', file_get_contents($full_path), $type)) { + if (preg_match('|Template Post Type:(.*)$|mi', file_get_contents($fullPath), $type)) { $types = explode(',', _cleanup_header_comment($type[1])); } - $file = $this->files->getRelativePath("{$path}/", $full_path); + $file = $this->files->getRelativePath("{$path}/", $fullPath); foreach ($types as $type) { $type = sanitize_key($type); @@ -110,16 +110,16 @@ protected function getTemplates($post_type = '', $text_domain = '') } } - if ($text_domain) { + if ($textDomain) { foreach ($templates as $type => $files) { foreach ($files as $file => $name) { - $templates[$type][$file] = translate($name, $text_domain); + $templates[$type][$file] = translate($name, $textDomain); } } } wp_cache_add('acorn/post_templates', $templates, 'themes'); - return $templates[$post_type] ?? []; + return $templates[$postType] ?? []; } } diff --git a/src/Roots/Acorn/View/Composers/Concerns/AcfFields.php b/src/Roots/Acorn/View/Composers/Concerns/AcfFields.php index 398615af..d6e040b2 100644 --- a/src/Roots/Acorn/View/Composers/Concerns/AcfFields.php +++ b/src/Roots/Acorn/View/Composers/Concerns/AcfFields.php @@ -10,12 +10,12 @@ trait AcfFields /** * ACF data to be passed to the view before rendering. * - * @param int $post_id + * @param int $postId * @return array */ - protected function fields($post_id = null) + protected function fields($postId = null) { - return collect(\get_fields($post_id)) + return collect(\get_fields($postId)) ->mapWithKeys(function ($value, $key) { $value = is_array($value) ? new Fluent($value) : $value; $method = Str::camel($key); diff --git a/tests/Application/BootloaderTest.php b/tests/Application/BootloaderTest.php index 732e4a5d..39704f44 100644 --- a/tests/Application/BootloaderTest.php +++ b/tests/Application/BootloaderTest.php @@ -32,34 +32,34 @@ }); it('should set the basePath if composer.json exists in theme', function () { - $composer_path = $this->fixture('base_path/base_composer'); + $composerPath = $this->fixture('base_path/base_composer'); - $this->stub('get_theme_file_path', fn ($path) => "{$composer_path}/{$path}"); + $this->stub('get_theme_file_path', fn ($path) => "{$composerPath}/{$path}"); $app = (new Bootloader)->getApplication(); - expect($app->basePath())->toBe($composer_path); + expect($app->basePath())->toBe($composerPath); }); it('should set the basePath if app exists in theme', function () { - $app_path = $this->fixture('base_path/base_app'); - $this->stub('get_theme_file_path', fn () => $app_path); + $appPath = $this->fixture('base_path/base_app'); + $this->stub('get_theme_file_path', fn () => $appPath); $app = Bootloader::getInstance()->getApplication(); - expect($app->basePath())->toBe(dirname($app_path)); + expect($app->basePath())->toBe(dirname($appPath)); }); it('should set the basePath if composer.json exists as ancestor of ../../../', function () { $files = mock(\Roots\Acorn\Filesystem\Filesystem::class); $this->stub('get_theme_file_path', fn () => ''); - $composer_path = $this->fixture('base_path/base_composer'); + $composerPath = $this->fixture('base_path/base_composer'); - $files->shouldReceive('closest')->andReturn("{$composer_path}/composer.json"); + $files->shouldReceive('closest')->andReturn("{$composerPath}/composer.json"); $files->shouldReceive('ensureDirectoryExists'); $app = (new Bootloader(null, $files))->getApplication(); - expect($app->basePath())->toBe($composer_path); + expect($app->basePath())->toBe($composerPath); }); From 3ffa6ffb8454cbecfb5ab5977d6811e85711f478 Mon Sep 17 00:00:00 2001 From: Tommi Carleman Date: Mon, 11 Dec 2023 12:46:57 +0100 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=92=A5=20use=20`realpath()`=20before?= =?UTF-8?q?=20including=20view=20(#319)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Sage/ViewFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Sage/ViewFinder.php b/src/Roots/Acorn/Sage/ViewFinder.php index 057e9210..6d3e85c3 100644 --- a/src/Roots/Acorn/Sage/ViewFinder.php +++ b/src/Roots/Acorn/Sage/ViewFinder.php @@ -39,7 +39,7 @@ public function __construct(FileViewFinder $finder, Filesystem $files, $path = ' { $this->finder = $finder; $this->files = $files; - $this->path = $path ? realpath($path) : get_theme_file_path(); + $this->path = realpath($path ? $path : get_theme_file_path()); } /** From fed7493e684b0e9d05761a9cb86e784e250fc17b Mon Sep 17 00:00:00 2001 From: Joshua Fredrickson Date: Mon, 11 Dec 2023 05:47:41 -0600 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=92=A5=20add=20relativePath=20to=20As?= =?UTF-8?q?set=20contract=20(#268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Assets/Contracts/Asset.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Roots/Acorn/Assets/Contracts/Asset.php b/src/Roots/Acorn/Assets/Contracts/Asset.php index 12145849..51c1a4ff 100644 --- a/src/Roots/Acorn/Assets/Contracts/Asset.php +++ b/src/Roots/Acorn/Assets/Contracts/Asset.php @@ -30,6 +30,14 @@ 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. + * @return string + */ + public function relativePath(string $base_path): string; + /** * Get data URL of asset. * From 658a267b9bb1f8b908138df28478a634beaa896c Mon Sep 17 00:00:00 2001 From: QWp6t Date: Mon, 11 Dec 2023 03:58:08 -0800 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=9A=A8=20code=20styles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Assets/Contracts/Asset.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Roots/Acorn/Assets/Contracts/Asset.php b/src/Roots/Acorn/Assets/Contracts/Asset.php index 51c1a4ff..dccf2741 100644 --- a/src/Roots/Acorn/Assets/Contracts/Asset.php +++ b/src/Roots/Acorn/Assets/Contracts/Asset.php @@ -33,8 +33,7 @@ public function contents(); /** * Get the relative path to the asset. * - * @param string $base_path Base path to use for relative path. - * @return string + * @param string $base_path Base path to use for relative path. */ public function relativePath(string $base_path): string; From 3b9d58f38fe7e279dd9d41e213550c505b2d5453 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Mon, 11 Dec 2023 10:46:37 -0600 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=93=9D=20Update=20README=20[ci=20skip?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fdd44400..4fc1b60d 100644 --- a/README.md +++ b/README.md @@ -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).
-KM Digital Carrot WordPress.com Worksite Safety Freave +KM Digital Carrot WordPress.com Worksite Safety Copia Digital Freave
## Overview From 735cb593970b49618c4fd727fdfcaf45033fd5d8 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 22 Dec 2023 17:04:34 -0800 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=9A=A9=20remove=20experimental=20flag?= =?UTF-8?q?=20(#318)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/config/app/.env.example | 2 - README.md | 2 +- composer.json | 1 + src/Roots/Acorn/Application.php | 7 -- src/Roots/Acorn/Bootloader.php | 24 +--- .../Console/Commands/RouteCacheCommand.php | 94 --------------- src/Roots/Acorn/Kernel.php | 111 ------------------ 7 files changed, 4 insertions(+), 237 deletions(-) delete mode 100644 src/Roots/Acorn/Kernel.php diff --git a/.devcontainer/config/app/.env.example b/.devcontainer/config/app/.env.example index 96f53b3c..97c8f6d4 100644 --- a/.devcontainer/config/app/.env.example +++ b/.devcontainer/config/app/.env.example @@ -17,5 +17,3 @@ AUTH_SALT='generateme' SECURE_AUTH_SALT='generateme' LOGGED_IN_SALT='generateme' NONCE_SALT='generateme' - -ACORN_ENABLE_EXPERIMENTAL_ROUTER='true' diff --git a/README.md b/README.md index 4fc1b60d..c959a9d4 100644 --- a/README.md +++ b/README.md @@ -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 | 🟢 | | diff --git a/composer.json b/composer.json index e492f27b..020ba092 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Roots/Acorn/Application.php b/src/Roots/Acorn/Application.php index 68006172..2412333b 100644 --- a/src/Roots/Acorn/Application.php +++ b/src/Roots/Acorn/Application.php @@ -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; @@ -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); - } } diff --git a/src/Roots/Acorn/Bootloader.php b/src/Roots/Acorn/Bootloader.php index f33315a1..3009d196 100644 --- a/src/Roots/Acorn/Bootloader.php +++ b/src/Roots/Acorn/Bootloader.php @@ -114,16 +114,7 @@ public function boot($callback = null) return class_exists('WP_CLI') ? $this->bootWpCli($app) : $this->bootConsole($app); } - if (Application::isExperimentalRouterEnabled()) { - $app->singleton( - \Illuminate\Contracts\Http\Kernel::class, - \Roots\Acorn\Http\Kernel::class - ); - - return $this->bootHttp($app); - } - - return $this->bootWordPress($app); + return $this->bootHttp($app); } /** @@ -246,17 +237,6 @@ protected function bootHttp(ApplicationContract $app) }); } - /** - * Boot the Application for WordPress requests. - * - * @return void - */ - protected function bootWordPress(ApplicationContract $app) - { - $app->make(\Illuminate\Contracts\Http\Kernel::class) - ->handle(\Illuminate\Http\Request::capture()); - } - /** * Get Application instance. * @@ -268,7 +248,7 @@ public function getApplication(): ApplicationContract $this->app->singleton( \Illuminate\Contracts\Http\Kernel::class, - \Roots\Acorn\Kernel::class + \Roots\Acorn\Http\Kernel::class ); $this->app->singleton( diff --git a/src/Roots/Acorn/Console/Commands/RouteCacheCommand.php b/src/Roots/Acorn/Console/Commands/RouteCacheCommand.php index 563333b7..a4238258 100644 --- a/src/Roots/Acorn/Console/Commands/RouteCacheCommand.php +++ b/src/Roots/Acorn/Console/Commands/RouteCacheCommand.php @@ -3,13 +3,7 @@ namespace Roots\Acorn\Console\Commands; use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract; -use Illuminate\Filesystem\Filesystem; -use Roots\Acorn\Application; use Roots\Acorn\Console\Concerns\GetsFreshApplication; -use Roots\Acorn\Console\Console; -use Symfony\Component\Process\Exception\ProcessSignaledException; -use Symfony\Component\Process\Exception\RuntimeException; -use Symfony\Component\Process\Process; class RouteCacheCommand extends \Illuminate\Foundation\Console\RouteCacheCommand { @@ -17,94 +11,6 @@ class RouteCacheCommand extends \Illuminate\Foundation\Console\RouteCacheCommand getFreshApplication as protected parentGetFreshApplication; } - protected $console; - - public function __construct(Filesystem $files, Console $console) - { - parent::__construct($files); - - $this->console = $console; - } - - /** - * Execute the console command. - * - * @return void - */ - public function handle() - { - if (! Application::isExperimentalRouterEnabled()) { - return; - } - - if (! $this->ensureDependenciesExist()) { - return; - } - - parent::handle(); - } - - /** - * Ensure the dependencies for the database commands are available. - * - * @return bool - */ - protected function ensureDependenciesExist() - { - if (class_exists(\Laravel\SerializableClosure\SerializableClosure::class)) { - return true; - } - - $message = 'Route caching requires Serializable Closure (laravel/serializable-closure) package.'; - - if ($this->components->confirm("{$message} Would you like to install it?")) { - $this->installDependencies(); - if ($this->console->acorn('route:cache') === 0) { - $this->components->info('Routes cached successfully.'); - } - } else { - $this->components->error($message); - } - - return false; - } - - /** - * Install the command's dependencies. - * - * @return void - * - * @throws \Symfony\Component\Process\Exception\ProcessSignaledException - * - * @copyright Taylor Otwell - * - * @link https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Console/DatabaseInspectionCommand.php - */ - protected function installDependencies() - { - $command = collect($this->console->findComposer()) - ->push('require laravel/serializable-closure') - ->implode(' '); - - $process = Process::fromShellCommandline($command, null, null, null, null); - - if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { - try { - $process->setTty(true); - } catch (RuntimeException $e) { - $this->components->warn($e->getMessage()); - } - } - - try { - $process->run(fn ($type, $line) => $this->output->write($line)); - } catch (ProcessSignaledException $e) { - if (extension_loaded('pcntl') && $e->getSignal() !== SIGINT) { - throw $e; - } - } - } - /** * Get a fresh application instance. * diff --git a/src/Roots/Acorn/Kernel.php b/src/Roots/Acorn/Kernel.php deleted file mode 100644 index dbf9a4d2..00000000 --- a/src/Roots/Acorn/Kernel.php +++ /dev/null @@ -1,111 +0,0 @@ -app = $app; - } - - /** - * Bootstrap the application for HTTP requests. - * - * @return void - */ - public function bootstrap() - { - if (! $this->app->hasBeenBootstrapped()) { - $this->app->bootstrapWith($this->bootstrappers()); - } - } - - /** - * Handle an incoming HTTP request. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function handle($request) - { - $this->app->instance('request', $request); - - Facade::clearResolvedInstance('request'); - - $this->bootstrap(); - } - - /** - * Call the terminate method on any terminable middleware. - * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Http\Response $response - * @return void - */ - public function terminate($request, $response) - { - //... - } - - /** - * Get the bootstrap classes for the application. - * - * @return array - */ - protected function bootstrappers() - { - return $this->bootstrappers; - } - - /** - * Get the Laravel application instance. - * - * @return \Illuminate\Contracts\Foundation\Application - */ - public function getApplication() - { - return $this->app; - } - - /** - * Set the Laravel application instance. - * - * @return $this - */ - public function setApplication(Application $app) - { - $this->app = $app; - - return $this; - } -} From 5b188cef18775b0eb9ff9448acd4a6ba442457bc Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 22 Dec 2023 19:05:00 -0600 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=8E=A8=20Remove=20`with()`=20from=20t?= =?UTF-8?q?he=20composer=20stub=20(#323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Console/Commands/stubs/composer.stub | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Roots/Acorn/Console/Commands/stubs/composer.stub b/src/Roots/Acorn/Console/Commands/stubs/composer.stub index 5d4638fe..f5e0c134 100644 --- a/src/Roots/Acorn/Console/Commands/stubs/composer.stub +++ b/src/Roots/Acorn/Console/Commands/stubs/composer.stub @@ -14,16 +14,4 @@ class DummyClass extends Composer protected static $views = [ DummyViews ]; - - /** - * Data to be passed to view before rendering. - * - * @return array - */ - public function with() - { - return [ - // - ]; - } }