Refactor all env variables into Env class.

This commit is contained in:
marco
2015-08-08 22:35:46 +02:00
parent a06919054d
commit 34153e8df6
4 changed files with 19 additions and 4 deletions

View File

@ -4,7 +4,15 @@ namespace MailPoet\Config;
if(!defined('ABSPATH')) exit;
class Env {
public static $version;
public static $plugin_name;
public static $file;
public static $path;
public static $views_path;
public static $assets_path;
public static $assets_url;
public static $languages_path;
public static $lib_path;
public static $plugin_prefix;
public static $db_prefix;
public static $db_source_name;
@ -14,9 +22,17 @@ class Env {
public static $db_password;
public static $db_charset;
public static function init() {
public static function init($file, $version) {
global $wpdb;
self::$version = $version;
self::$plugin_name = 'mailpoet';
self::$file = $file;
self::$path = dirname(self::$file);
self::$views_path = self::$path . '/views';
self::$assets_path = self::$path . '/assets';
self::$assets_url = plugins_url('/assets', $file);
self::$languages_path = self::$path . '/lang';
self::$lib_path = self::$path . '/lib';
self::$plugin_prefix = 'mailpoet_';
self::$db_prefix = $wpdb->prefix . self::$plugin_prefix;
self::$db_source_name = self::dbSourceName();

View File

@ -18,7 +18,7 @@ class Initializer {
'file' => '',
'version' => '1.0.0'
)) {
Env::init();
Env::init($params['file'], $params['version']);
$this->setup_db();
$this->data = array();

View File

@ -4,7 +4,7 @@ use \MailPoet\Config\Env;
class EnvCest {
function _before() {
Env::init();
Env::init('file', '1.0.0');
}
function itCanReturnThePluginPrefix() {

View File

@ -1,5 +1,4 @@
<?php
use \MailPoet\Config\Env;
$wordpress_path = getenv('WP_TEST_PATH');