| 1 |
<?php |
| 2 |
|
| 3 |
namespace Allex; |
| 4 |
|
| 5 |
use Allex\Module\Addons; |
| 6 |
use Allex\Module\Assets; |
| 7 |
use Allex\Module\Reviews; |
| 8 |
use Allex\Module\Upgrade; |
| 9 |
|
| 10 |
class Container extends \Pimple\Container |
| 11 |
{ |
| 12 |
public function __construct(array $values = []) |
| 13 |
{ |
| 14 |
parent::__construct($values); |
| 15 |
|
| 16 |
/** |
| 17 |
* @param $c |
| 18 |
* |
| 19 |
* @return string |
| 20 |
*/ |
| 21 |
$this['VERSION'] = function ($c) { |
| 22 |
return '0.6.8'; |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* @param $c |
| 27 |
* |
| 28 |
* @return mixed |
| 29 |
*/ |
| 30 |
$this['PLUGIN_BASENAME'] = function ($c) use ($values) { |
| 31 |
return $values['PLUGIN_BASENAME']; |
| 32 |
}; |
| 33 |
|
| 34 |
/** |
| 35 |
* @param $c |
| 36 |
* |
| 37 |
* @return bool|string |
| 38 |
*/ |
| 39 |
$this['FRAMEWORK_BASE_PATH'] = function ($c) { |
| 40 |
// Added slashes to prevent issues in Windows machines, where the backslash where interpreted as escape char. |
| 41 |
$dir = __DIR__; |
| 42 |
|
| 43 |
$dir = str_replace('\\', '/', __DIR__); |
| 44 |
|
| 45 |
if (DIRECTORY_SEPARATOR == '\\') { |
| 46 |
$dir = str_replace('\\', '/', $dir); |
| 47 |
} |
| 48 |
|
| 49 |
return realpath($dir . '/../'); |
| 50 |
}; |
| 51 |
|
| 52 |
/** |
| 53 |
* @param $c |
| 54 |
* |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
$this['TWIG_PATH'] = function ($c) { |
| 58 |
return $c['FRAMEWORK_BASE_PATH'] . '/twig'; |
| 59 |
}; |
| 60 |
|
| 61 |
/** |
| 62 |
* @param $c |
| 63 |
* |
| 64 |
* @return string |
| 65 |
*/ |
| 66 |
$this['ASSETS_BASE_URL'] = function ($c) { |
| 67 |
$frameworkPath = $c['FRAMEWORK_BASE_PATH']; |
| 68 |
|
| 69 |
if (DIRECTORY_SEPARATOR == '\\') { |
| 70 |
$frameworkPath = str_replace('\\', '/', $frameworkPath); |
| 71 |
} |
| 72 |
|
| 73 |
$wpContentDir = WP_CONTENT_DIR; |
| 74 |
if (DIRECTORY_SEPARATOR == '\\') { |
| 75 |
$wpContentDir = str_replace('\\', '/', $wpContentDir); |
| 76 |
} |
| 77 |
|
| 78 |
// Some servers have a weird ABSPATH, so we make a minor adjustment here. |
| 79 |
if (ABSPATH === '//') { |
| 80 |
$wpContentDir = str_replace('//', '/', $wpContentDir); |
| 81 |
} |
| 82 |
|
| 83 |
$relativePath = str_replace($wpContentDir, '', $frameworkPath); |
| 84 |
|
| 85 |
$baseUrl = str_replace(['https://', 'http://'], '//', WP_CONTENT_URL); |
| 86 |
|
| 87 |
return $baseUrl . $relativePath . '/assets'; |
| 88 |
}; |
| 89 |
|
| 90 |
/** |
| 91 |
* @param $c |
| 92 |
* |
| 93 |
* @return mixed |
| 94 |
*/ |
| 95 |
$this['PLUGIN_NAME'] = function ($c) { |
| 96 |
return str_replace('.php', '', basename($c['PLUGIN_BASENAME'])); |
| 97 |
}; |
| 98 |
|
| 99 |
/** |
| 100 |
* @param $c |
| 101 |
* |
| 102 |
* @return mixed |
| 103 |
*/ |
| 104 |
$this['PLUGIN_TITLE'] = function ($c) { |
| 105 |
if (is_admin()) { |
| 106 |
if (!function_exists('get_plugin_data')) { |
| 107 |
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 108 |
} |
| 109 |
|
| 110 |
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $c['PLUGIN_BASENAME']); |
| 111 |
|
| 112 |
return $data['Name']; |
| 113 |
} |
| 114 |
|
| 115 |
return $c['PLUGIN_NAME']; |
| 116 |
}; |
| 117 |
|
| 118 |
/** |
| 119 |
* @param $c |
| 120 |
* |
| 121 |
* @return string |
| 122 |
*/ |
| 123 |
$this['EDD_API_URL'] = function ($c) use ($values) { |
| 124 |
return $values['EDD_API_URL']; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
/** |
| 129 |
* @param $c |
| 130 |
* |
| 131 |
* @return string |
| 132 |
*/ |
| 133 |
$this['UPDATES_DOC_URL'] = function ($c) use ($values) { |
| 134 |
return $values['UPDATES_DOC_URL']; |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* @param $c |
| 140 |
* |
| 141 |
* @return string |
| 142 |
*/ |
| 143 |
$this['PLUGIN_AUTHOR'] = function ($c) use ($values) { |
| 144 |
return $values['PLUGIN_AUTHOR']; |
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
* @param $c |
| 150 |
* |
| 151 |
* @return Textdomain |
| 152 |
*/ |
| 153 |
$this['textdomain'] = function ($c) { |
| 154 |
return new Textdomain($c); |
| 155 |
}; |
| 156 |
|
| 157 |
/** |
| 158 |
* @param $c |
| 159 |
* |
| 160 |
* @return \Twig_Loader_Filesystem |
| 161 |
*/ |
| 162 |
$this['twig_loader_filesystem'] = function ($c) { |
| 163 |
return new \Twig_Loader_Filesystem($c['TWIG_PATH']); |
| 164 |
}; |
| 165 |
|
| 166 |
/** |
| 167 |
* @param $c |
| 168 |
* |
| 169 |
* @return \Twig_Environment |
| 170 |
*/ |
| 171 |
$this['twig'] = function ($c) { |
| 172 |
$twig = new \Twig_Environment( |
| 173 |
$c['twig_loader_filesystem'], |
| 174 |
// [ 'debug' => true ] |
| 175 |
[] |
| 176 |
); |
| 177 |
|
| 178 |
// $twig->addExtension(new \Twig_Extension_Debug()); |
| 179 |
|
| 180 |
return $twig; |
| 181 |
}; |
| 182 |
|
| 183 |
/** |
| 184 |
* @param $c |
| 185 |
* |
| 186 |
* @return Upgrade |
| 187 |
*/ |
| 188 |
$this['module_upgrade'] = function ($c) { |
| 189 |
return new Upgrade($c); |
| 190 |
}; |
| 191 |
|
| 192 |
/** |
| 193 |
* @param $c |
| 194 |
* |
| 195 |
* @return Assets |
| 196 |
*/ |
| 197 |
$this['module_assets'] = function ($c) { |
| 198 |
return new Assets($c); |
| 199 |
}; |
| 200 |
|
| 201 |
/** |
| 202 |
* @param $c |
| 203 |
* |
| 204 |
* @return Reviews |
| 205 |
*/ |
| 206 |
$this['module_reviews'] = function ($c) { |
| 207 |
return new Reviews($c); |
| 208 |
}; |
| 209 |
|
| 210 |
/** |
| 211 |
* @param $c |
| 212 |
* |
| 213 |
* @return Addons |
| 214 |
*/ |
| 215 |
$this['module_addons'] = function ($c) { |
| 216 |
return new Addons($c); |
| 217 |
}; |
| 218 |
} |
| 219 |
} |
| 220 |
|