mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
b9af2d0734
Remove PHP 5.5 from Travis configuration. Dotenv used for environment management now, examples and tests updated to use putenv instead of define. Logger alias update to LoggerInterface. Update mutable config API calls. Replace array declaration with short version: []. Update license year.
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\EnvironmentCheck\Checks;
|
|
|
|
use SilverStripe\Control\Director;
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
|
|
/**
|
|
* Check that a given URL is functioning, by default, the homepage.
|
|
*
|
|
* Note that Director::test() will be used rather than a CURL check.
|
|
*
|
|
* @package environmentcheck
|
|
*/
|
|
class URLCheck implements EnvironmentCheck
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $url;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $testString;
|
|
|
|
/**
|
|
* @param string $url The URL to check, relative to the site (homepage is '').
|
|
* @param string $testString An optional piece of text to search for on the homepage.
|
|
*/
|
|
public function __construct($url = '', $testString = '')
|
|
{
|
|
$this->url = $url;
|
|
$this->testString = $testString;
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*
|
|
* @return array
|
|
* @throws HTTPResponse_Exception
|
|
*/
|
|
public function check()
|
|
{
|
|
$response = Director::test($this->url);
|
|
|
|
if ($response->getStatusCode() != 200) {
|
|
return [
|
|
EnvironmentCheck::ERROR,
|
|
sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode())
|
|
];
|
|
} elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) {
|
|
return [
|
|
EnvironmentCheck::WARNING,
|
|
sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString)
|
|
];
|
|
}
|
|
return [
|
|
EnvironmentCheck::OK,
|
|
sprintf('Success retrieving "%s"', $this->url)
|
|
];
|
|
}
|
|
}
|