Skip to content

Commit

Permalink
🎨 Change variables/properties from snake_case to camelCase (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Dec 11, 2023
1 parent 0b3c66e commit 670abe8
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 95 deletions.
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();
})();
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/Roots/Acorn/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function registerGlobalHelpers()
*/
public function usePaths(array $paths)
{
$supported_paths = [
$supportedPaths = [
'app' => 'appPath',
'lang' => 'langPath',
'config' => 'configPath',
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand Down
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
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
14 changes: 7 additions & 7 deletions src/Roots/Acorn/Bootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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)
};
Expand Down
4 changes: 2 additions & 2 deletions src/Roots/Acorn/Bootstrap/RegisterConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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);

$kernel->commands();

$command = implode(' ', $args);

foreach ($assoc_args as $key => $value) {
foreach ($assocArgs as $key => $value) {
$command .= " {$this->formatOption($key, $value)}";
}

Expand Down
Loading

0 comments on commit 670abe8

Please sign in to comment.