-
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.
- Loading branch information
Showing
16 changed files
with
323 additions
and
13 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,57 @@ | ||
<?php | ||
namespace Health\Checks\File; | ||
|
||
use Health\Checks\BaseCheck; | ||
|
||
abstract class Base extends BaseCheck | ||
{ | ||
|
||
/** | ||
* List of files | ||
* | ||
* @var array | ||
*/ | ||
protected $files = []; | ||
|
||
/** | ||
* | ||
* @param array $params | ||
*/ | ||
public function __construct(array $params = []) | ||
{ | ||
parent::__construct($params); | ||
|
||
$this->files = $this->getParam('files', []); | ||
} | ||
|
||
/** | ||
* | ||
* {@inheritdoc} | ||
* @see \Health\Checks\HealthCheckInterface::call() | ||
*/ | ||
public function call() | ||
{ | ||
$builder = $this->getBuilder(); | ||
|
||
$errors = []; | ||
|
||
foreach ($this->files as $file) { | ||
if (! is_file($file) || ! $this->isValid($file)) { | ||
$errors[] = $file; | ||
} | ||
} | ||
|
||
if ($errors) { | ||
$builder->down()->withData('errors', $errors); | ||
} | ||
|
||
return $builder->withData('files', $this->files)->build(); | ||
} | ||
|
||
/** | ||
* | ||
* @param string $file | ||
* @return boolean | ||
*/ | ||
abstract protected function isValid($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,18 @@ | ||
<?php | ||
namespace Health\Checks\File; | ||
|
||
use Health\Checks\HealthCheckInterface; | ||
|
||
class Ini extends Base implements HealthCheckInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @param string $file | ||
* @return boolean | ||
*/ | ||
protected function isValid($file) | ||
{ | ||
return @parse_ini_file($file) !== false; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
namespace Health\Checks\File; | ||
|
||
use Health\Checks\HealthCheckInterface; | ||
|
||
class Json extends Base implements HealthCheckInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @param string $file | ||
* @return boolean | ||
*/ | ||
protected function isValid($file) | ||
{ | ||
return ! is_null(json_decode(@file_get_contents($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,34 @@ | ||
<?php | ||
namespace Health\Checks\File; | ||
|
||
use Health\Checks\HealthCheckInterface; | ||
use Symfony\Component\Yaml\Exception\ParseException; | ||
use Symfony\Component\Yaml\Parser; | ||
|
||
class Yaml extends Base implements HealthCheckInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @param string $file | ||
* @return boolean | ||
*/ | ||
protected function isValid($file) | ||
{ | ||
if (function_exists('yaml_parse_file')) { | ||
return (@yaml_parse_file($file) === false) ? false : true; | ||
} | ||
|
||
if (class_exists('Symfony\Component\Yaml\Parser')) { | ||
try { | ||
(new Parser())->parse(file_get_contents($file)); | ||
} catch (ParseException $e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
namespace Tests\Checks; | ||
|
||
use Health\Checks\File\Ini; | ||
|
||
class FileIniTest extends CheckTestCase | ||
{ | ||
|
||
public function testCheckFile() | ||
{ | ||
$this->assertCheck($this->runCheck(Ini::class, []), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Ini::class, [ | ||
'files' => [ | ||
'./tests/files/valid.ini' | ||
] | ||
]), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Ini::class, [ | ||
'files' => [ | ||
'./tests/files/invalid.ini' | ||
] | ||
]), 'DOWN'); | ||
|
||
$this->assertCheck($this->runCheck(Ini::class, [ | ||
'files' => [ | ||
'./tests/files/notfound.ini' | ||
] | ||
]), 'DOWN'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
namespace Tests\Checks; | ||
|
||
use Health\Checks\File\Json; | ||
|
||
class FileJsonTest extends CheckTestCase | ||
{ | ||
|
||
public function testCheckFile() | ||
{ | ||
$this->assertCheck($this->runCheck(Json::class, []), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Json::class, [ | ||
'files' => [ | ||
'./tests/files/valid.json' | ||
] | ||
]), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Json::class, [ | ||
'files' => [ | ||
'./tests/files/invalid.json.txt' | ||
] | ||
]), 'DOWN'); | ||
|
||
$this->assertCheck($this->runCheck(Json::class, [ | ||
'files' => [ | ||
'./tests/files/notfound.json' | ||
] | ||
]), 'DOWN'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
namespace Tests\Checks; | ||
|
||
use Health\Checks\File\Yaml; | ||
|
||
class FileYamlTest extends CheckTestCase | ||
{ | ||
|
||
public function testCheckFile() | ||
{ | ||
$this->assertCheck($this->runCheck(Yaml::class, []), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Yaml::class, [ | ||
'files' => [ | ||
'./tests/files/valid.yaml' | ||
] | ||
]), 'UP'); | ||
|
||
$this->assertCheck($this->runCheck(Yaml::class, [ | ||
'files' => [ | ||
'./tests/files/invalid.yaml.txt' | ||
] | ||
]), 'DOWN'); | ||
|
||
$this->assertCheck($this->runCheck(Yaml::class, [ | ||
'files' => [ | ||
'./tests/files/notfound.yaml' | ||
] | ||
]), 'DOWN'); | ||
} | ||
} |
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,3 @@ | ||
; comment text | ||
|
||
#@!#@!# |
Oops, something went wrong.