Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3namespace MediaWiki\Extension\CommunityConfiguration\Validation;
4
5use Iterator;
6use LogicException;
7use MediaWiki\Extension\CommunityConfiguration\Schema\SchemaBuilder;
8
9/**
10 * Validator that can validate a config page
11 *
12 * @note ValidatorFactory constructs validators in a service-like way (construct it once and then
13 * keep the instance for all future calls). Do not keep state in your class when implementing a
14 * validator.
15 */
16interface IValidator {
17
18    /**
19     * Validate passed config strictly
20     *
21     * All validations errors from the library will make this validation fail.
22     *
23     * This is executed by WikiPageConfigWriter _before_ writing a config (for edits made
24     * via GrowthExperiments-provided interface), and by ConfigHooks for manual edits.
25     *
26     * @param mixed $config Associative array representing config that's going to be validated
27     * @return ValidationStatus
28     */
29    public function validateStrictly( $config ): ValidationStatus;
30
31    /**
32     * Validate passed config permissively
33     *
34     * This will not return a fatal StatusValue if required attributes are missing or if there are extra attributes,
35     * but it will add warnings instead.
36     * It will still return a fatal StatusValue for all other types of errors,
37     * for example if a value is of the wrong type.
38     *
39     * This is used by WikiPageConfigLoader before returning the config (this is to ensure invalid config is never used)
40     *
41     * When writing a config, use @see validateStrictly() instead of this.
42     *
43     * @param mixed $config Associative array representing config that's going to be validated
44     * @return ValidationStatus
45     */
46    public function validatePermissively( $config ): ValidationStatus;
47
48    /**
49     * Are configuration schemas supported?
50     *
51     * @return bool
52     */
53    public function areSchemasSupported(): bool;
54
55    /**
56     * Return a SchemaBuilder object
57     *
58     * Callers need to check areSchemasSupported() returns true first.
59     *
60     * @return SchemaBuilder
61     * @throws LogicException if called when areSchemasSupported() returns false
62     */
63    public function getSchemaBuilder(): SchemaBuilder;
64
65    /**
66     * Return a schema Iterator that allows all internal
67     * sub-schemas to be iterated.
68     *
69     * Callers need to check areSchemasSupported() returns true first.
70     *
71     * @return Iterator
72     * @throws LogicException if called when areSchemasSupported() returns false
73     */
74    public function getSchemaIterator(): Iterator;
75
76    /**
77     * Return current version for the schema
78     *
79     * Only safe to call when areSchemasSupported() returns true.
80     *
81     * @return string|null
82     */
83    public function getSchemaVersion(): ?string;
84}