MediaWiki  1.30.0
GadgetDefinitionValidator.php
Go to the documentation of this file.
1 <?php
2 
14  protected static $propertyValidation = [
15  'settings' => [ 'is_array', 'array' ],
16  'settings.rights' => [ 'is_array', 'array' , 'is_string', 'string' ],
17  'settings.default' => [ 'is_bool', 'boolean' ],
18  'settings.hidden' => [ 'is_bool', 'boolean' ],
19  'settings.skins' => [ [ __CLASS__, 'isArrayOrTrue' ], 'array or true', 'is_string', 'string' ],
20  'settings.category' => [ 'is_string', 'string' ],
21  'module' => [ 'is_array', 'array' ],
22  'module.scripts' => [ 'is_array', 'array', 'is_string', 'string' ],
23  'module.styles' => [ 'is_array', 'array', 'is_string', 'string' ],
24  'module.dependencies' => [ 'is_array', 'array', 'is_string', 'string' ],
25  'module.peers' => [ 'is_array', 'array', 'is_string', 'string' ],
26  'module.messages' => [ 'is_array', 'array', 'is_string', 'string' ],
27  'module.type' => [ 'is_string', 'string' ],
28  ];
29 
34  public static function isArrayOrTrue( $value ) {
35  return is_array( $value ) || $value === true;
36  }
37 
44  public function validate( array $properties, $tolerateMissing = false ) {
45  foreach ( self::$propertyValidation as $property => $validation ) {
46  $path = explode( '.', $property );
47  $val = $properties;
48 
49  // Walk down and verify that the path from the root to this property exists
50  foreach ( $path as $p ) {
51  if ( !array_key_exists( $p, $val ) ) {
52  if ( $tolerateMissing ) {
53  // Skip validation of this property altogether
54  continue 2;
55  } else {
56  return Status::newFatal( 'gadgets-validate-notset', $property );
57  }
58  }
59  $val = $val[$p];
60  }
61 
62  // Do the actual validation of this property
63  $func = $validation[0];
64  if ( !call_user_func( $func, $val ) ) {
65  return Status::newFatal(
66  'gadgets-validate-wrongtype',
67  $property,
68  $validation[1],
69  gettype( $val )
70  );
71  }
72 
73  if ( isset( $validation[2] ) && is_array( $val ) ) {
74  // Descend into the array and check the type of each element
75  $func = $validation[2];
76  foreach ( $val as $i => $v ) {
77  if ( !call_user_func( $func, $v ) ) {
78  return Status::newFatal(
79  'gadgets-validate-wrongtype',
80  "{$property}[{$i}]",
81  $validation[3],
82  gettype( $v )
83  );
84  }
85  }
86  }
87  }
88 
89  return Status::newGood();
90  }
91 }
GadgetDefinitionValidator\isArrayOrTrue
static isArrayOrTrue( $value)
Definition: GadgetDefinitionValidator.php:34
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
GadgetDefinitionValidator\$propertyValidation
static $propertyValidation
Validation metadata.
Definition: GadgetDefinitionValidator.php:14
GadgetDefinitionValidator\validate
validate(array $properties, $tolerateMissing=false)
Check the validity of the given properties array.
Definition: GadgetDefinitionValidator.php:44
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$property
$property
Definition: styleTest.css.php:44
$value
$value
Definition: styleTest.css.php:45
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
GadgetDefinitionValidator
Class responsible for validating Gadget definition contents.
Definition: GadgetDefinitionValidator.php:8
$path
$path
Definition: NoLocalSettings.php:26
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
array
the array() calling protocol came about after MediaWiki 1.4rc1.