17 public function __construct() {
19 if ( class_exists( RomaricDrigon\MetaYaml\MetaYaml::class ) ) {
20 $this->baseSchema = $this->getBaseSchema();
34 if ( !is_callable( $callback ) ) {
35 $callback =
static function ( $unused1, $unused2, $unused3 ) {
44 if ( is_array( $this->baseSchema ) ) {
45 foreach ( $configurations as $index => $config ) {
48 $groups[$config[
'BASIC'][
'id']] = $config;
49 }
catch ( Exception $e ) {
50 $callback( $index, $config, $e->getMessage() );
54 foreach ( $configurations as $index => $config ) {
55 if ( isset( $config[
'BASIC'][
'id'] ) ) {
56 $groups[$config[
'BASIC'][
'id']] = $config;
58 $callback( $index, $config,
'id is missing' );
73 return preg_split(
"/^---$/m", $data, -1, PREG_SPLIT_NO_EMPTY );
87 foreach ( $documents as $document ) {
90 if ( isset( $document[
'TEMPLATE'] ) ) {
91 $template = $document[
'TEMPLATE'];
93 $groups[] = $document;
98 foreach ( $groups as $i => $group ) {
101 if ( $groups[$i][
'BASIC'][
'class'] === AggregateMessageGroup::class ) {
102 unset( $groups[$i][
'FILES'] );
110 public function getBaseSchema() {
111 return TranslateYaml::load( __DIR__ .
'/data/group-yaml-schema.yaml' );
121 $schema = $this->baseSchema;
123 foreach ( $config as $section ) {
124 if ( !isset( $section[
'class'] ) ) {
128 $class = $section[
'class'];
132 if ( $class ===
'StringMatcher' ) {
133 $class = StringMatcher::class;
137 if ( !is_callable( [ $class,
'getExtraSchema' ] ) ) {
141 $extra = call_user_func( [ $class,
'getExtraSchema' ] );
142 $schema = array_replace_recursive( $schema, $extra );
145 $schema =
new RomaricDrigon\MetaYaml\MetaYaml( $schema );
146 $schema->validate( $config );
156 foreach ( $specific as $key => $value ) {
157 if ( is_array( $value ) && isset( $base[$key] ) && is_array( $base[$key] ) ) {
160 $base[$key] = $value;
Utility class to parse and validate message group configurations.
getDocumentsFromYaml( $data)
Given a Yaml string, returns the non-empty documents as an array.
parseDocuments(array $documents)
Returns group configurations from YAML documents.
getHopefullyValidConfigurations( $data, $callback=null)
Easy to use function to get valid group configurations from YAML.
static mergeTemplate(array $base, array $specific)
Merges a document template (base) to actual definition (specific)
validate(array $config)
Validates group configuration against schema.
static loadString( $text)