mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 21:49:04 +01:00
Add parsers.use_php_yaml
option to decide PHP Yaml extension behavior
This commit is contained in:
parent
43a052cd53
commit
26156abc2f
@ -74,6 +74,7 @@ class Formwork
|
||||
'content.path' => ROOT_PATH . 'content' . DS,
|
||||
'content.extension' => '.md',
|
||||
'files.allowed_extensions' => array('.jpg', '.jpeg', '.png', '.gif', '.svg', '.pdf'),
|
||||
'parsers.use_php_yaml' => 'parse',
|
||||
'templates.path' => ROOT_PATH . 'templates' . DS,
|
||||
'templates.extension' => '.php',
|
||||
'pages.index' => 'index',
|
||||
|
@ -2,14 +2,17 @@
|
||||
|
||||
namespace Formwork\Parsers;
|
||||
|
||||
use Formwork\Core\Formwork;
|
||||
use Formwork\Utils\FileSystem;
|
||||
use Spyc;
|
||||
|
||||
class YAML
|
||||
{
|
||||
public static $PHPYAMLmode;
|
||||
|
||||
public static function parse($input)
|
||||
{
|
||||
if (function_exists('yaml_parse')) {
|
||||
if (function_exists('yaml_parse') && static::PHPYAMLmode('parse')) {
|
||||
if (!preg_match('/^---\n/', $input)) {
|
||||
$input = "---\n" . $input;
|
||||
}
|
||||
@ -25,7 +28,7 @@ class YAML
|
||||
|
||||
public static function encode($data)
|
||||
{
|
||||
if (function_exists('yaml_emit')) {
|
||||
if (function_exists('yaml_emit') && static::PHPYAMLmode('emit')) {
|
||||
if (empty($data)) {
|
||||
return '';
|
||||
}
|
||||
@ -33,4 +36,29 @@ class YAML
|
||||
}
|
||||
return Spyc::YAMLDump($data, false, 0, true);
|
||||
}
|
||||
|
||||
protected static function PHPYAMLmode($pattern)
|
||||
{
|
||||
if (is_null(static::$PHPYAMLmode)) {
|
||||
$option = Formwork::instance()->option('parsers.use_php_yaml');
|
||||
if ($option) {
|
||||
switch (strtolower($option)) {
|
||||
case 'all':
|
||||
static::$PHPYAMLmode = 'all';
|
||||
break;
|
||||
case 'emit':
|
||||
static::$PHPYAMLmode = 'emit';
|
||||
break;
|
||||
case 'parse':
|
||||
static::$PHPYAMLmode = 'parse';
|
||||
break;
|
||||
case 'none':
|
||||
default:
|
||||
static::$PHPYAMLmode = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return static::$PHPYAMLmode === $pattern || static::$PHPYAMLmode == 'all';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user