Skip to content

Commit

Permalink
Fix to coding standards as best we can
Browse files Browse the repository at this point in the history
Will have to wait for other #14 and #15 to be merged to do it properly
  • Loading branch information
rosswintle committed Nov 12, 2021
1 parent 3167989 commit 38b7662
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
20 changes: 14 additions & 6 deletions app/App.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<?php
/**
* Class to initialize the application
*/

namespace DeliciousBrains\SpinupWPComposerSite;

/**
* App class to initialize the application
*/
class App {

/**
* Load custom site code
* Load custom site code
*/
public function register() {
}

/**
* Helper for defining constants if not already defined.
*
* @param string $key
* @param mixed $value
* @param string $key The name of the constant to define
* @param mixed $value The value to give the constant
*/
public static function define( $key, $value ) {
if ( defined( $key ) ) {
Expand All @@ -25,8 +31,10 @@ public static function define( $key, $value ) {
}

/**
* @param $name
* @param $arguments
* This allows the environment to be queried using magic methods like App::is_env_<environment>
*
* @param string $name The name of the magic method
* @param $arguments The arguments to the magic method
*
* @return bool
*/
Expand All @@ -36,4 +44,4 @@ public static function __callStatic( $name, $arguments ) {
return $env === env( 'WP_ENV' );
}
}
}
}
41 changes: 20 additions & 21 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Your base production configuration goes in this file. Environment-specific
* overrides go in their respective config/environments/{{WP_ENV}}.php file.
Expand All @@ -9,7 +8,7 @@
* can.
*/

use \DeliciousBrains\SpinupWPComposerSite\App;
use DeliciousBrains\SpinupWPComposerSite\App;

$root_dir = dirname( __DIR__ );
$webroot_dir = $root_dir . '/public';
Expand All @@ -23,7 +22,7 @@
* Use Dotenv to set required environment variables and load .env file in root
*/
$env_files = file_exists( $root_dir . '/.env.local' ) ? [ '.env', '.env.local' ] : [ '.env' ];
$dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir, $env_files, false);
$dotenv = Dotenv\Dotenv::createUnsafeImmutable( $root_dir, $env_files, false );
if ( file_exists( $root_dir . '/.env' ) ) {
$dotenv->load();
$dotenv->required( [ 'DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL' ] );
Expand All @@ -40,36 +39,36 @@
App::define( 'WP_CONTENT_DIR', $webroot_dir . CONTENT_DIR );
App::define( 'WP_CONTENT_URL', WP_HOME . CONTENT_DIR );

App::define('DB_NAME', env('DB_NAME'));
App::define('DB_USER', env('DB_USER'));
App::define('DB_PASSWORD', env('DB_PASSWORD'));
App::define('DB_HOST', env('DB_HOST') ?: 'localhost');
App::define('DB_CHARSET', 'utf8mb4');
App::define('DB_COLLATE', '');
$table_prefix = env('DB_PREFIX') ?: 'wp_';
App::define( 'DB_NAME', env( 'DB_NAME' ) );
App::define( 'DB_USER', env( 'DB_USER' ) );
App::define( 'DB_PASSWORD', env( 'DB_PASSWORD' ) );
App::define( 'DB_HOST', env( 'DB_HOST' ) ?: 'localhost' );
App::define( 'DB_CHARSET', 'utf8mb4' );
App::define( 'DB_COLLATE', '' );
$table_prefix = env( 'DB_PREFIX' ) ?: 'wp_';

// Set other constants from env file.
foreach( array_keys($dotenv->load()) as $key ) {
App::define($key, env( $key ));
foreach ( array_keys( $dotenv->load() ) as $key ) {
App::define( $key, env( $key ) );
}

// Environment config
// Environment config.
$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';
if ( file_exists( $env_config ) ) {
require_once $env_config;
}

App::define('AUTOMATIC_UPDATER_DISABLED', true);
App::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
// Disable the plugin and theme file editor in the admin
App::define('DISALLOW_FILE_EDIT', true);
// Disable plugin and theme updates and installation from the admin
App::define('DISALLOW_FILE_MODS', true);
App::define( 'AUTOMATIC_UPDATER_DISABLED', true );
App::define( 'DISABLE_WP_CRON', env( 'DISABLE_WP_CRON' ) ?: false );
// Disable the plugin and theme file editor in the admin.
App::define( 'DISALLOW_FILE_EDIT', true );
// Disable plugin and theme updates and installation from the admin.
App::define( 'DISALLOW_FILE_MODS', true );

// Secret keys
// Secret keys.
if ( ! file_exists( __DIR__ . '/keys.php' ) ) {
$keys = file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' );
file_put_contents( __DIR__ . '/keys.php', '<?php use ' . App::class . '; ' . str_replace( 'define(', 'App::define(', $keys ) );
file_put_contents( __DIR__ . '/keys.php', '<?php use ' . App::class . ";\n" . str_replace( 'define(', 'App::define(', $keys ) );
}
include __DIR__ . '/keys.php';

Expand Down
7 changes: 5 additions & 2 deletions public/content/mu-plugins/app.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php
// Bootstrap our site code
( new DeliciousBrains\SpinupWPComposerSite\App() )->register();
/**
* Bootstrap our site code
*/

( new DeliciousBrains\SpinupWPComposerSite\App() )->register();
4 changes: 2 additions & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @var bool
*/
define('WP_USE_THEMES', true);
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
2 changes: 1 addition & 1 deletion public/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*/
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
require_once dirname( __DIR__ ) . '/config/app.php';
require_once ABSPATH . 'wp-settings.php';
require_once ABSPATH . 'wp-settings.php';

0 comments on commit 38b7662

Please sign in to comment.