openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit a0d3c2d63a562920bc410e2130bc212edfa471e9
parent d1a314a30d61c12cc640c82d07177dbe60368e2b
Author: Jan Dankert <develop@jandankert.de>
Date:   Fri, 15 Nov 2019 22:57:50 +0100

Refactoring: Wrapping the Spyc YAML implementation.

Diffstat:
modules/cms-api/API.class.php | 2+-
modules/cms-core/Dispatcher.class.php | 2+-
modules/cms-core/action/ConfigurationAction.class.php | 2+-
modules/cms-core/action/ElementAction.class.php | 2+-
modules/cms-core/action/ObjectAction.class.php | 2+-
modules/cms-core/model/BaseObject.class.php | 4++--
modules/cms-core/model/Element.class.php | 2+-
modules/configuration/ConfigurationLoader.class.php | 2+-
modules/language/Language.class.php | 4++--
modules/util/YAML.class.php | 50++++++++++++++++++++++++++++++++++++++++++++++++++
modules/util/require.php | 1+
11 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/modules/cms-api/API.class.php b/modules/cms-api/API.class.php @@ -125,7 +125,7 @@ class API case CMS_API_OUTPUT_YAML: header('Content-Type: application/yaml; charset=UTF-8'); - $spyc = new \Spyc(); + $spyc = new \YAML(); $output = $spyc->dump($data); break; } diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -70,7 +70,7 @@ class Dispatcher // Sollte nur 1x pro Sitzung ausgeführt werden. Wie ermitteln wir das? //if ( DEVELOPMENT ) - // Logger::debug( "Effective configuration:\n".Spyc::YAMLDump($conf) ); + // Logger::debug( "Effective configuration:\n".YAML::YAMLDump($conf) ); if (!empty($conf['security']['umask'])) umask(octdec($conf['security']['umask'])); diff --git a/modules/cms-core/action/ConfigurationAction.class.php b/modules/cms-core/action/ConfigurationAction.class.php @@ -97,7 +97,7 @@ class ConfigurationAction extends BaseAction } }); - $this->setTemplateVar('source',\Spyc::YAMLDump($conf,4,0,true)); + $this->setTemplateVar('source',\YAML::dump($conf,4,0,true)); } diff --git a/modules/cms-core/action/ElementAction.class.php b/modules/cms-core/action/ElementAction.class.php @@ -455,7 +455,7 @@ class ElementAction extends BaseAction $this->setTemplateVar('dynamic_class_description',$description ); $this->setTemplateVar('dynamic_class_parameters' ,$paramList ); - $this->setTemplateVar('parameters' ,\Spyc::YAMLDump($parameters) ); + $this->setTemplateVar('parameters' ,\YAML::dump($parameters) ); break; diff --git a/modules/cms-core/action/ObjectAction.class.php b/modules/cms-core/action/ObjectAction.class.php @@ -575,7 +575,7 @@ class ObjectAction extends BaseAction // Validate YAML-Settings try { - \Spyc::YAMLLoad( $this->baseObject->settings); + \YAML::parse( $this->baseObject->settings); } catch( \Exception $e ) { diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php @@ -6,7 +6,7 @@ namespace cms\model; use ArrayUtils; use cms\publish\Publish; use phpseclib\Math\BigInteger; -use Spyc; +use YAML; use template_engine\components\ElseComponent; /** @@ -1334,7 +1334,7 @@ SQL */ public function getSettings() { - $settings = Spyc::YAMLLoadString($this->settings); + $settings = YAML::parse($this->settings); // pass-by-reference array_walk_recursive($settings, function (&$item, $key) { diff --git a/modules/cms-core/model/Element.class.php b/modules/cms-core/model/Element.class.php @@ -537,7 +537,7 @@ SQL // Fixing old syntax ("key:value") to valid YAML syntax. $this->code = preg_replace( '/^(\w+)\:(.+)$/m','${1}: ${2}', $this->code ); - $items = \Spyc::YAMLLoadString( $this->code ); + $items = \YAML::parse( $this->code ); Logger::trace('dynamic-parameters: '.print_r($items,true)); diff --git a/modules/configuration/ConfigurationLoader.class.php b/modules/configuration/ConfigurationLoader.class.php @@ -66,7 +66,7 @@ class ConfigurationLoader return array(); } - $customConfig = Spyc::YAMLLoad( $configFile ); + $customConfig = YAML::parse( $configFile ); // Resolve variables in all custom configuration values array_walk_recursive( $customConfig, function(&$value,$key) diff --git a/modules/language/Language.class.php b/modules/language/Language.class.php @@ -3,7 +3,7 @@ namespace language; use LogicException; -use Spyc; +use YAML; class Language { @@ -57,7 +57,7 @@ class Language private function getLanguageSource() { - return Spyc::YAMLLoad( $this->srcFile); + return YAML::parse( $this->srcFile); } diff --git a/modules/util/YAML.class.php b/modules/util/YAML.class.php @@ -0,0 +1,49 @@ +<?php + +use Spyc; + +/** + * YAML Wrapper for the Spyc implementation of a YAML-Parser. + */ +class YAML +{ + /** + * Load a string of YAML into a PHP array statically. + * + * The load method, when supplied with a YAML string, will do its best + * to convert YAML in a string into a PHP array. Pretty simple. + + * @param $string + * @return array + */ + public static function parse($string) + { + return Spyc::YAMLLoadString($string); + } + + /** + * Dump YAML from PHP array statically + * + * The dump method, when supplied with an array, will do its best + * to convert the array into friendly YAML. Pretty simple. Feel free to + * save the returned string as nothing.yaml and pass it around. + * + * Oh, and you can decide how big the indent is and what the wordwrap + * for folding is. Pretty cool -- just pass in 'false' for either if + * you want to use the default. + * + * Indent's default is 2 spaces, wordwrap's default is 40 characters. And + * you can turn off wordwrap by passing in 0. + * + * @access public + * @return string + * @param array|\stdClass $array PHP array + * @param int $indent Pass in false to use the default, which is 2 + * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) + * @param bool $no_opening_dashes Do not start YAML file with "---\n" + */ + public static function dump($array, $indent = false, $wordwrap = false, $no_opening_dashes = false) + { + return Spyc::YAMLDump( $array,$indent,$wordwrap,$no_opening_dashes ); + } +}+ \ No newline at end of file diff --git a/modules/util/require.php b/modules/util/require.php @@ -24,6 +24,7 @@ require_once( __DIR__.'/'.'Less.php' ); require_once( __DIR__.'/'.'JSqueeze.class.php' ); require_once( __DIR__.'/'.'Parsedown.class.php' ); require_once( __DIR__.'/'.'Spyc.class.php' ); +require_once( __DIR__.'/'.'YAML.class.php' ); require_once( __DIR__.'/'.'TreeElement.class.php' ); require_once( __DIR__.'/'.'Tree.class.php'); require_once( __DIR__.'/'.'Macro.class.php' );