-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add php dotenv support for config file
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Database | ||
DB_NAME=aztecwpdevenv | ||
DB_USER=root | ||
DB_PASSWORD= | ||
DB_HOST=localhost | ||
DB_CHARSET=utf8 | ||
DB_COLLATE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Project files | ||
/public/ | ||
/tmp/ | ||
!/public/wp-config.php | ||
.salts | ||
|
||
# Eclipse Project | ||
.settings/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
</rule> | ||
|
||
<!-- Sniff the theme files --> | ||
<file>./theme/src/</file> | ||
<file>./src/</file> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* The base configuration for WordPress | ||
* | ||
* The wp-config.php creation script uses this file during the | ||
* installation. You don't have to use the web site, you can | ||
* copy this file to "wp-config.php" and fill in the values. | ||
* | ||
* This file contains the following configurations: | ||
* | ||
* * MySQL settings | ||
* * Secret keys | ||
* * Database table prefix | ||
* * ABSPATH | ||
* | ||
* @link https://codex.wordpress.org/Editing_wp-config.php | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
$root_dir = __DIR__ . '/../'; | ||
|
||
require_once $root_dir . '/vendor/autoload.php'; | ||
|
||
// Load main env file | ||
$dotenv = new Dotenv\Dotenv( $root_dir ); | ||
$dotenv->load(); | ||
|
||
// Load auto-generated salts file | ||
$dotenv = new Dotenv\Dotenv( $root_dir, '.salts' ); | ||
$dotenv->load(); | ||
|
||
// ** MySQL settings ** // | ||
/** The name of the database for WordPress */ | ||
define( 'DB_NAME', getenv( 'DB_NAME' ) ); | ||
|
||
/** MySQL database username */ | ||
define( 'DB_USER', getenv( 'DB_USER' )); | ||
|
||
/** MySQL database password */ | ||
define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) ); | ||
|
||
/** MySQL hostname */ | ||
define( 'DB_HOST', getenv( 'DB_HOST' ) ); | ||
|
||
/** Database Charset to use in creating database tables. */ | ||
define( 'DB_CHARSET', getenv( 'DB_CHARSET' ) ); | ||
|
||
/** The Database Collate type. Don't change this if in doubt. */ | ||
define( 'DB_COLLATE', getenv( 'DB_COLLATE' ) ); | ||
|
||
/** | ||
* Authentication Unique Keys and Salts. | ||
* | ||
* Change these to different unique phrases! | ||
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} | ||
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
define( 'AUTH_KEY', getenv( 'AUTH_KEY' ) ); | ||
define( 'SECURE_AUTH_KEY', getenv( 'SECURE_AUTH_KEY' ) ); | ||
define( 'LOGGED_IN_KEY', getenv( 'LOGGED_IN_KEY' ) ); | ||
define( 'NONCE_KEY', getenv( 'NONCE_KEY' ) ); | ||
define( 'AUTH_SALT', getenv( 'AUTH_SALT' ) ); | ||
define( 'SECURE_AUTH_SALT', getenv( 'SECURE_AUTH_SALT' ) ); | ||
define( 'LOGGED_IN_SALT', getenv( 'LOGGED_IN_SALT' ) ); | ||
define( 'NONCE_SALT', getenv( 'NONCE_SALT' ) ); | ||
|
||
/** | ||
* WordPress Database Table prefix. | ||
* | ||
* You can have multiple installations in one database if you give each | ||
* a unique prefix. Only numbers, letters, and underscores please! | ||
*/ | ||
$table_prefix = 'wp_'; | ||
|
||
|
||
|
||
|
||
/* That's all, stop editing! Happy blogging. */ | ||
|
||
/** Absolute path to the WordPress directory. */ | ||
if ( ! defined( 'ABSPATH' ) ) | ||
define( 'ABSPATH', dirname( __FILE__ ) . '/' ); | ||
|
||
/** Sets up WordPress vars and included files. */ | ||
require_once ABSPATH . 'wp-settings.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Dotenv WP CLI command hooks | ||
* | ||
* @package AztecWpDevEnv | ||
*/ | ||
|
||
namespace AztecWpDevEnv\WP_CLI; | ||
|
||
/** | ||
* Add new functionalities to the WP CLI dot env command | ||
*/ | ||
class Dotenv { | ||
|
||
/** | ||
* Ensure that the salts file exist | ||
* | ||
* If the file salts doesn't exist, the salts aren't generated | ||
*/ | ||
public function ensure_salts_file() { | ||
$salts_file = __DIR__ . '/../../.salts'; | ||
|
||
if ( ! file_exists( $salts_file ) ) { | ||
if ( ! touch( $salts_file ) ) { | ||
\WP_CLI::error( 'Cannot create the salts file.' ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
use AztecWpDevEnv\WP_CLI\Dotenv as Aztec_WP_CLI_Dotenv; | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
if ( ! class_exists( WP_CLI::class ) ) { | ||
require_once __DIR__ . '/../../vendor/wp-cli/wp-cli/php/class-wp-cli.php'; | ||
} | ||
|
||
$dot_env = new Aztec_WP_CLI_Dotenv(); | ||
|
||
\WP_CLI::add_hook( 'before_invoke:dotenv salts generate', array( $dot_env, 'ensure_salts_file' ) ); |