@@ -9,7 +9,6 @@ |
||
| 9 | 9 | use SilverStripe\Control\HTTPResponse; |
| 10 | 10 | use SilverStripe\Control\HTTPResponse_Exception; |
| 11 | 11 | use SilverStripe\Control\RequestHandler; |
| 12 | -use SilverStripe\Core\Config\Config; |
|
| 13 | 12 | use SilverStripe\Core\Injector\Injector; |
| 14 | 13 | use SilverStripe\Dev\Deprecation; |
| 15 | 14 | use SilverStripe\EnvironmentCheck\EnvironmentCheck; |
@@ -25,291 +25,291 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class EnvironmentChecker extends RequestHandler |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - private static $url_handlers = [ |
|
| 32 | - '' => 'index', |
|
| 33 | - ]; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $checkSuiteName; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - protected $title; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var int |
|
| 47 | - */ |
|
| 48 | - protected $errorCode = 500; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var null|string |
|
| 52 | - */ |
|
| 53 | - private static $to_email_address = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var null|string |
|
| 57 | - */ |
|
| 58 | - private static $from_email_address = null; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - private static $email_results = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var bool Log results via {@link \Psr\Log\LoggerInterface} |
|
| 67 | - */ |
|
| 68 | - private static $log_results_warning = false; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string Maps to {@link \Psr\Log\LogLevel} levels. Defaults to LogLevel::WARNING |
|
| 72 | - */ |
|
| 73 | - private static $log_results_warning_level = LogLevel::WARNING; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var bool Log results via a {@link \Psr\Log\LoggerInterface} |
|
| 77 | - */ |
|
| 78 | - private static $log_results_error = false; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var int Maps to {@link \Psr\Log\LogLevel} levels. Defaults to LogLevel::ALERT |
|
| 82 | - */ |
|
| 83 | - private static $log_results_error_level = LogLevel::ALERT; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $checkSuiteName |
|
| 87 | - * @param string $title |
|
| 88 | - */ |
|
| 89 | - public function __construct($checkSuiteName, $title) |
|
| 90 | - { |
|
| 91 | - parent::__construct(); |
|
| 92 | - |
|
| 93 | - $this->checkSuiteName = $checkSuiteName; |
|
| 94 | - $this->title = $title; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param string $permission |
|
| 99 | - * |
|
| 100 | - * @throws HTTPResponse_Exception |
|
| 101 | - */ |
|
| 102 | - public function init($permission = 'ADMIN') |
|
| 103 | - { |
|
| 104 | - // if the environment supports it, provide a basic auth challenge and see if it matches configured credentials |
|
| 105 | - if (getenv('ENVCHECK_BASICAUTH_USERNAME') && getenv('ENVCHECK_BASICAUTH_PASSWORD')) { |
|
| 106 | - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 107 | - // authenticate the input user/pass with the configured credentials |
|
| 108 | - if (!( |
|
| 109 | - $_SERVER['PHP_AUTH_USER'] == getenv('ENVCHECK_BASICAUTH_USERNAME') |
|
| 110 | - && $_SERVER['PHP_AUTH_PW'] == getenv('ENVCHECK_BASICAUTH_PASSWORD') |
|
| 111 | - ) |
|
| 112 | - ) { |
|
| 113 | - $response = new HTTPResponse(null, 401); |
|
| 114 | - $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\""); |
|
| 115 | - // Exception is caught by RequestHandler->handleRequest() and will halt further execution |
|
| 116 | - $e = new HTTPResponse_Exception(null, 401); |
|
| 117 | - $e->setResponse($response); |
|
| 118 | - throw $e; |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $response = new HTTPResponse(null, 401); |
|
| 122 | - $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\""); |
|
| 123 | - // Exception is caught by RequestHandler->handleRequest() and will halt further execution |
|
| 124 | - $e = new HTTPResponse_Exception(null, 401); |
|
| 125 | - $e->setResponse($response); |
|
| 126 | - throw $e; |
|
| 127 | - } |
|
| 128 | - } else { |
|
| 129 | - if (!$this->canAccess(null, $permission)) { |
|
| 130 | - return $this->httpError(403); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param null|int|Member $member |
|
| 137 | - * @param string $permission |
|
| 138 | - * |
|
| 139 | - * @return bool |
|
| 140 | - * |
|
| 141 | - * @throws HTTPResponse_Exception |
|
| 142 | - */ |
|
| 143 | - public function canAccess($member = null, $permission = 'ADMIN') |
|
| 144 | - { |
|
| 145 | - if (!$member) { |
|
| 146 | - $member = Member::currentUser(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if (!$member) { |
|
| 150 | - $member = BasicAuth::requireLogin('Environment Checker', $permission, false); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // We allow access to this controller regardless of live-status or ADMIN permission only |
|
| 154 | - // if on CLI. Access to this controller is always allowed in "dev-mode", or of the user is ADMIN. |
|
| 155 | - if (Director::isDev() |
|
| 156 | - || Director::is_cli() |
|
| 157 | - || empty($permission) |
|
| 158 | - || Permission::checkMember($member, $permission) |
|
| 159 | - ) { |
|
| 160 | - return true; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // Extended access checks. |
|
| 164 | - // "Veto" style, return NULL to abstain vote. |
|
| 165 | - $canExtended = null; |
|
| 166 | - $results = $this->extend('canAccess', $member); |
|
| 167 | - if ($results && is_array($results)) { |
|
| 168 | - if (!min($results)) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return HTTPResponse |
|
| 179 | - */ |
|
| 180 | - public function index() |
|
| 181 | - { |
|
| 182 | - $response = new HTTPResponse; |
|
| 183 | - $result = EnvironmentCheckSuite::inst($this->checkSuiteName)->run(); |
|
| 184 | - |
|
| 185 | - if (!$result->ShouldPass()) { |
|
| 186 | - $response->setStatusCode($this->errorCode); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $resultText = $result->customise([ |
|
| 190 | - 'URL' => Director::absoluteBaseURL(), |
|
| 191 | - 'Title' => $this->title, |
|
| 192 | - 'Name' => $this->checkSuiteName, |
|
| 193 | - 'ErrorCode' => $this->errorCode, |
|
| 194 | - ])->renderWith(__CLASS__); |
|
| 195 | - |
|
| 196 | - if ($this->config()->get('email_results') && !$result->ShouldPass()) { |
|
| 197 | - $email = new Email( |
|
| 198 | - $this->config()->get('from_email_address'), |
|
| 199 | - $this->config()->get('to_email_address'), |
|
| 200 | - $this->title, |
|
| 201 | - $resultText |
|
| 202 | - ); |
|
| 203 | - $email->send(); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // Optionally log errors and warnings individually |
|
| 207 | - foreach ($result->Details() as $detail) { |
|
| 208 | - if ($this->config()->get('log_results_warning') && $detail->StatusCode == EnvironmentCheck::WARNING) { |
|
| 209 | - $this->log( |
|
| 210 | - sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message), |
|
| 211 | - $this->config()->get('log_results_warning_level') |
|
| 212 | - ); |
|
| 213 | - } elseif ($this->config()->get('log_results_error') && $detail->StatusCode == EnvironmentCheck::ERROR) { |
|
| 214 | - $this->log( |
|
| 215 | - sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message), |
|
| 216 | - $this->config()->get('log_results_error_level') |
|
| 217 | - ); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // output the result as JSON if requested |
|
| 222 | - if ($this->getRequest()->getExtension() == 'json' |
|
| 223 | - || strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false |
|
| 224 | - ) { |
|
| 225 | - $response->setBody($result->toJSON()); |
|
| 226 | - $response->addHeader('Content-Type', 'application/json'); |
|
| 227 | - return $response; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $response->setBody($resultText); |
|
| 231 | - |
|
| 232 | - return $response; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Sends a log entry to the configured PSR-3 LoggerInterface |
|
| 237 | - * |
|
| 238 | - * @param string $message |
|
| 239 | - * @param int $level |
|
| 240 | - */ |
|
| 241 | - public function log($message, $level) |
|
| 242 | - { |
|
| 243 | - Injector::inst()->get(LoggerInterface::class)->log($level, $message); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Set the HTTP status code that should be returned when there's an error. |
|
| 248 | - * |
|
| 249 | - * @param int $errorCode |
|
| 250 | - */ |
|
| 251 | - public function setErrorCode($errorCode) |
|
| 252 | - { |
|
| 253 | - $this->errorCode = $errorCode; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @deprecated |
|
| 258 | - * @param string $from |
|
| 259 | - */ |
|
| 260 | - public static function set_from_email_address($from) |
|
| 261 | - { |
|
| 262 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 263 | - static::config()->set('from_email_address', $from); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @deprecated |
|
| 268 | - * @return null|string |
|
| 269 | - */ |
|
| 270 | - public static function get_from_email_address() |
|
| 271 | - { |
|
| 272 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 273 | - return static::config()->get('from_email_address'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @deprecated |
|
| 278 | - * @param string $to |
|
| 279 | - */ |
|
| 280 | - public static function set_to_email_address($to) |
|
| 281 | - { |
|
| 282 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 283 | - static::config()->set('to_email_address', $to); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @deprecated |
|
| 288 | - * @return null|string |
|
| 289 | - */ |
|
| 290 | - public static function get_to_email_address() |
|
| 291 | - { |
|
| 292 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 293 | - return static::config()->get('to_email_address'); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @deprecated |
|
| 298 | - * @param bool $results |
|
| 299 | - */ |
|
| 300 | - public static function set_email_results($results) |
|
| 301 | - { |
|
| 302 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 303 | - static::config()->set('email_results', $results); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @deprecated |
|
| 308 | - * @return bool |
|
| 309 | - */ |
|
| 310 | - public static function get_email_results() |
|
| 311 | - { |
|
| 312 | - Deprecation::notice('2.0', 'Use config API instead'); |
|
| 313 | - return static::config()->get('email_results'); |
|
| 314 | - } |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + private static $url_handlers = [ |
|
| 32 | + '' => 'index', |
|
| 33 | + ]; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $checkSuiteName; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + protected $title; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var int |
|
| 47 | + */ |
|
| 48 | + protected $errorCode = 500; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var null|string |
|
| 52 | + */ |
|
| 53 | + private static $to_email_address = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var null|string |
|
| 57 | + */ |
|
| 58 | + private static $from_email_address = null; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + private static $email_results = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var bool Log results via {@link \Psr\Log\LoggerInterface} |
|
| 67 | + */ |
|
| 68 | + private static $log_results_warning = false; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string Maps to {@link \Psr\Log\LogLevel} levels. Defaults to LogLevel::WARNING |
|
| 72 | + */ |
|
| 73 | + private static $log_results_warning_level = LogLevel::WARNING; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var bool Log results via a {@link \Psr\Log\LoggerInterface} |
|
| 77 | + */ |
|
| 78 | + private static $log_results_error = false; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var int Maps to {@link \Psr\Log\LogLevel} levels. Defaults to LogLevel::ALERT |
|
| 82 | + */ |
|
| 83 | + private static $log_results_error_level = LogLevel::ALERT; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $checkSuiteName |
|
| 87 | + * @param string $title |
|
| 88 | + */ |
|
| 89 | + public function __construct($checkSuiteName, $title) |
|
| 90 | + { |
|
| 91 | + parent::__construct(); |
|
| 92 | + |
|
| 93 | + $this->checkSuiteName = $checkSuiteName; |
|
| 94 | + $this->title = $title; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param string $permission |
|
| 99 | + * |
|
| 100 | + * @throws HTTPResponse_Exception |
|
| 101 | + */ |
|
| 102 | + public function init($permission = 'ADMIN') |
|
| 103 | + { |
|
| 104 | + // if the environment supports it, provide a basic auth challenge and see if it matches configured credentials |
|
| 105 | + if (getenv('ENVCHECK_BASICAUTH_USERNAME') && getenv('ENVCHECK_BASICAUTH_PASSWORD')) { |
|
| 106 | + if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 107 | + // authenticate the input user/pass with the configured credentials |
|
| 108 | + if (!( |
|
| 109 | + $_SERVER['PHP_AUTH_USER'] == getenv('ENVCHECK_BASICAUTH_USERNAME') |
|
| 110 | + && $_SERVER['PHP_AUTH_PW'] == getenv('ENVCHECK_BASICAUTH_PASSWORD') |
|
| 111 | + ) |
|
| 112 | + ) { |
|
| 113 | + $response = new HTTPResponse(null, 401); |
|
| 114 | + $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\""); |
|
| 115 | + // Exception is caught by RequestHandler->handleRequest() and will halt further execution |
|
| 116 | + $e = new HTTPResponse_Exception(null, 401); |
|
| 117 | + $e->setResponse($response); |
|
| 118 | + throw $e; |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $response = new HTTPResponse(null, 401); |
|
| 122 | + $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\""); |
|
| 123 | + // Exception is caught by RequestHandler->handleRequest() and will halt further execution |
|
| 124 | + $e = new HTTPResponse_Exception(null, 401); |
|
| 125 | + $e->setResponse($response); |
|
| 126 | + throw $e; |
|
| 127 | + } |
|
| 128 | + } else { |
|
| 129 | + if (!$this->canAccess(null, $permission)) { |
|
| 130 | + return $this->httpError(403); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param null|int|Member $member |
|
| 137 | + * @param string $permission |
|
| 138 | + * |
|
| 139 | + * @return bool |
|
| 140 | + * |
|
| 141 | + * @throws HTTPResponse_Exception |
|
| 142 | + */ |
|
| 143 | + public function canAccess($member = null, $permission = 'ADMIN') |
|
| 144 | + { |
|
| 145 | + if (!$member) { |
|
| 146 | + $member = Member::currentUser(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if (!$member) { |
|
| 150 | + $member = BasicAuth::requireLogin('Environment Checker', $permission, false); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // We allow access to this controller regardless of live-status or ADMIN permission only |
|
| 154 | + // if on CLI. Access to this controller is always allowed in "dev-mode", or of the user is ADMIN. |
|
| 155 | + if (Director::isDev() |
|
| 156 | + || Director::is_cli() |
|
| 157 | + || empty($permission) |
|
| 158 | + || Permission::checkMember($member, $permission) |
|
| 159 | + ) { |
|
| 160 | + return true; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // Extended access checks. |
|
| 164 | + // "Veto" style, return NULL to abstain vote. |
|
| 165 | + $canExtended = null; |
|
| 166 | + $results = $this->extend('canAccess', $member); |
|
| 167 | + if ($results && is_array($results)) { |
|
| 168 | + if (!min($results)) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return HTTPResponse |
|
| 179 | + */ |
|
| 180 | + public function index() |
|
| 181 | + { |
|
| 182 | + $response = new HTTPResponse; |
|
| 183 | + $result = EnvironmentCheckSuite::inst($this->checkSuiteName)->run(); |
|
| 184 | + |
|
| 185 | + if (!$result->ShouldPass()) { |
|
| 186 | + $response->setStatusCode($this->errorCode); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $resultText = $result->customise([ |
|
| 190 | + 'URL' => Director::absoluteBaseURL(), |
|
| 191 | + 'Title' => $this->title, |
|
| 192 | + 'Name' => $this->checkSuiteName, |
|
| 193 | + 'ErrorCode' => $this->errorCode, |
|
| 194 | + ])->renderWith(__CLASS__); |
|
| 195 | + |
|
| 196 | + if ($this->config()->get('email_results') && !$result->ShouldPass()) { |
|
| 197 | + $email = new Email( |
|
| 198 | + $this->config()->get('from_email_address'), |
|
| 199 | + $this->config()->get('to_email_address'), |
|
| 200 | + $this->title, |
|
| 201 | + $resultText |
|
| 202 | + ); |
|
| 203 | + $email->send(); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // Optionally log errors and warnings individually |
|
| 207 | + foreach ($result->Details() as $detail) { |
|
| 208 | + if ($this->config()->get('log_results_warning') && $detail->StatusCode == EnvironmentCheck::WARNING) { |
|
| 209 | + $this->log( |
|
| 210 | + sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message), |
|
| 211 | + $this->config()->get('log_results_warning_level') |
|
| 212 | + ); |
|
| 213 | + } elseif ($this->config()->get('log_results_error') && $detail->StatusCode == EnvironmentCheck::ERROR) { |
|
| 214 | + $this->log( |
|
| 215 | + sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message), |
|
| 216 | + $this->config()->get('log_results_error_level') |
|
| 217 | + ); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // output the result as JSON if requested |
|
| 222 | + if ($this->getRequest()->getExtension() == 'json' |
|
| 223 | + || strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false |
|
| 224 | + ) { |
|
| 225 | + $response->setBody($result->toJSON()); |
|
| 226 | + $response->addHeader('Content-Type', 'application/json'); |
|
| 227 | + return $response; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $response->setBody($resultText); |
|
| 231 | + |
|
| 232 | + return $response; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Sends a log entry to the configured PSR-3 LoggerInterface |
|
| 237 | + * |
|
| 238 | + * @param string $message |
|
| 239 | + * @param int $level |
|
| 240 | + */ |
|
| 241 | + public function log($message, $level) |
|
| 242 | + { |
|
| 243 | + Injector::inst()->get(LoggerInterface::class)->log($level, $message); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Set the HTTP status code that should be returned when there's an error. |
|
| 248 | + * |
|
| 249 | + * @param int $errorCode |
|
| 250 | + */ |
|
| 251 | + public function setErrorCode($errorCode) |
|
| 252 | + { |
|
| 253 | + $this->errorCode = $errorCode; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @deprecated |
|
| 258 | + * @param string $from |
|
| 259 | + */ |
|
| 260 | + public static function set_from_email_address($from) |
|
| 261 | + { |
|
| 262 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 263 | + static::config()->set('from_email_address', $from); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @deprecated |
|
| 268 | + * @return null|string |
|
| 269 | + */ |
|
| 270 | + public static function get_from_email_address() |
|
| 271 | + { |
|
| 272 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 273 | + return static::config()->get('from_email_address'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @deprecated |
|
| 278 | + * @param string $to |
|
| 279 | + */ |
|
| 280 | + public static function set_to_email_address($to) |
|
| 281 | + { |
|
| 282 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 283 | + static::config()->set('to_email_address', $to); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @deprecated |
|
| 288 | + * @return null|string |
|
| 289 | + */ |
|
| 290 | + public static function get_to_email_address() |
|
| 291 | + { |
|
| 292 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 293 | + return static::config()->get('to_email_address'); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @deprecated |
|
| 298 | + * @param bool $results |
|
| 299 | + */ |
|
| 300 | + public static function set_email_results($results) |
|
| 301 | + { |
|
| 302 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 303 | + static::config()->set('email_results', $results); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @deprecated |
|
| 308 | + * @return bool |
|
| 309 | + */ |
|
| 310 | + public static function get_email_results() |
|
| 311 | + { |
|
| 312 | + Deprecation::notice('2.0', 'Use config API instead'); |
|
| 313 | + return static::config()->get('email_results'); |
|
| 314 | + } |
|
| 315 | 315 | } |
@@ -18,80 +18,80 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class EnvironmentCheckerTest extends SapphireTest |
| 20 | 20 | { |
| 21 | - protected $usesDatabase = true; |
|
| 21 | + protected $usesDatabase = true; |
|
| 22 | 22 | |
| 23 | - protected function tearDown() |
|
| 24 | - { |
|
| 25 | - EnvironmentCheckSuite::reset(); |
|
| 26 | - parent::tearDown(); |
|
| 27 | - } |
|
| 23 | + protected function tearDown() |
|
| 24 | + { |
|
| 25 | + EnvironmentCheckSuite::reset(); |
|
| 26 | + parent::tearDown(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function testOnlyLogsWithErrors() |
|
| 30 | - { |
|
| 31 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 32 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 29 | + public function testOnlyLogsWithErrors() |
|
| 30 | + { |
|
| 31 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 32 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 33 | 33 | |
| 34 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors()); |
|
| 34 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors()); |
|
| 35 | 35 | |
| 36 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 37 | - ->disableOriginalConstructor() |
|
| 38 | - ->setMethods(['log']) |
|
| 39 | - ->getMock(); |
|
| 36 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 37 | + ->disableOriginalConstructor() |
|
| 38 | + ->setMethods(['log']) |
|
| 39 | + ->getMock(); |
|
| 40 | 40 | |
| 41 | - $logger->expects($this->never())->method('log'); |
|
| 41 | + $logger->expects($this->never())->method('log'); |
|
| 42 | 42 | |
| 43 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 43 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 44 | 44 | |
| 45 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 46 | - } |
|
| 45 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testLogsWithWarnings() |
|
| 49 | - { |
|
| 50 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 51 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 48 | + public function testLogsWithWarnings() |
|
| 49 | + { |
|
| 50 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 51 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 52 | 52 | |
| 53 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 54 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 53 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 54 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 55 | 55 | |
| 56 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 57 | - ->disableOriginalConstructor() |
|
| 58 | - ->setMethods(['log']) |
|
| 59 | - ->getMock(); |
|
| 56 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 57 | + ->disableOriginalConstructor() |
|
| 58 | + ->setMethods(['log']) |
|
| 59 | + ->getMock(); |
|
| 60 | 60 | |
| 61 | - $logger->expects($this->once()) |
|
| 62 | - ->method('log') |
|
| 63 | - ->withConsecutive( |
|
| 64 | - $this->equalTo(LogLevel::WARNING), |
|
| 65 | - $this->anything() |
|
| 66 | - ); |
|
| 61 | + $logger->expects($this->once()) |
|
| 62 | + ->method('log') |
|
| 63 | + ->withConsecutive( |
|
| 64 | + $this->equalTo(LogLevel::WARNING), |
|
| 65 | + $this->anything() |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 68 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 69 | 69 | |
| 70 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 71 | - } |
|
| 70 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function testLogsWithErrors() |
|
| 74 | - { |
|
| 75 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 76 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 73 | + public function testLogsWithErrors() |
|
| 74 | + { |
|
| 75 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 76 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 77 | 77 | |
| 78 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 79 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 78 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 79 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 80 | 80 | |
| 81 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 82 | - ->disableOriginalConstructor() |
|
| 83 | - ->setMethods(['log']) |
|
| 84 | - ->getMock(); |
|
| 81 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 82 | + ->disableOriginalConstructor() |
|
| 83 | + ->setMethods(['log']) |
|
| 84 | + ->getMock(); |
|
| 85 | 85 | |
| 86 | - $logger->expects($this->once()) |
|
| 87 | - ->method('log') |
|
| 88 | - ->withConsecutive( |
|
| 89 | - [$this->equalTo(LogLevel::ALERT), $this->anything()], |
|
| 90 | - [$this->equalTo(LogLevel::WARNING), $this->anything()] |
|
| 91 | - ); |
|
| 86 | + $logger->expects($this->once()) |
|
| 87 | + ->method('log') |
|
| 88 | + ->withConsecutive( |
|
| 89 | + [$this->equalTo(LogLevel::ALERT), $this->anything()], |
|
| 90 | + [$this->equalTo(LogLevel::WARNING), $this->anything()] |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 93 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 94 | 94 | |
| 95 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 96 | - } |
|
| 95 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckNoErrors implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::OK, '']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::OK, '']; |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckErrors implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::ERROR, 'test error']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::ERROR, 'test error']; |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckWarnings implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::WARNING, 'test warning']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::WARNING, 'test warning']; |
|
| 13 | + } |
|
| 14 | 14 | } |