mirror of
https://github.com/getgrav/grav.git
synced 2026-07-06 08:37:37 +02:00
Add yaml validation
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Grav\Common\Data;
|
||||
use Grav\Common\Grav;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* Data validation.
|
||||
@@ -624,6 +625,25 @@ class Validation
|
||||
return (array) $value;
|
||||
}
|
||||
|
||||
public static function typeYaml($value, $params)
|
||||
{
|
||||
try {
|
||||
Yaml::parse($value);
|
||||
return true;
|
||||
} catch (ParseException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function filterYaml($value, $params)
|
||||
{
|
||||
try {
|
||||
return (array) Yaml::parse($value);
|
||||
} catch (ParseException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom input: ignore (will not validate)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user