WPCF7_SWV_Schema{}└─ CompositeRule
The schema class as a composite rule.
Хуков нет.
Использование
$WPCF7_SWV_Schema = new WPCF7_SWV_Schema(); // use class methods
Методы
- public __construct( array $properties = [] )
- public validate( FormDataTree $form_data, array $context = [] )
- public toArray()
- public add_rule( AbstractRule $rule )
- public to_array()
Код WPCF7_SWV_Schema{} WPCF7 SWV Schema{} CF7 6.2.4.1
final class WPCF7_SWV_Schema extends CompositeRule {
/**
* The human-readable version of the schema.
*/
const version = 'SWV Core 2026-09-20';
/**
* Rule properties.
*/
public readonly string $locale;
/**
* Constructor.
*
* @param array $properties Rule properties.
*/
public function __construct( array $properties = [] ) {
$this->locale = $properties[ 'locale' ] ?? '';
}
/**
* Validates the form data according to the logic defined by this rule.
*
* @param FormDataTree $form_data Form data.
* @param array $context Optional context.
*/
public function validate( FormDataTree $form_data, array $context = [] ) {
foreach ( $this->rules() as $rule ) {
if ( $rule->matches( $context ) ) {
try {
$rule->validate( $form_data, $context );
} catch ( Invalidity $error ) {
yield new WP_Error( 'swv', $error->getMessage(), $error );
}
}
}
return true;
}
/**
* Returns an array that represents the rule properties.
*
* @return array Array of rule properties.
*/
public function toArray(): array {
$rules_arrays = array_map( static function ( $item ) {
return $item->toArray();
}, $this->rules() );
return array(
'version' => self::version,
'locale' => $this->locale,
'rules' => $rules_arrays,
);
}
/**
* Wrapper function for addRule.
*
* @param AbstractRule $rule Sub-rule to be added.
*/
public function add_rule( AbstractRule $rule ) {
return $this->addRule( $rule );
}
/**
* Wrapper function for toArray.
*
* @return array Array of rule properties.
*/
public function to_array() {
return $this->toArray();
}
}