DWS WP Framework
  • Welcome
  • Primary goals
    • Modular design
    • No 3rd-party dependencies
  • Key concepts and dev tools
    • PHP and WP requirements
    • Object-Oriented Programming
    • Semantic Versioning
    • Version Control (git / GitHub)
    • Dependency Management (Composer)
    • Automated Testing (Codeception + Github Actions)
    • Dependency Injection (PHP-DI)
    • Coding Standards (PHPCS and PHPMD)
    • Dependencies Scoping (PHP-Scoper)
    • TypeScript and Sass
    • Task Runners (Grunt)
  • Setting up your dev environment
    • Windows
  • Your first plugin
    • Multiple plugins using the framework on the same site
  • Frequently Asked Questions
  • Bootstrapper Module
    • Motivation
    • How it works
    • How to use
    • White Labeling
  • Helpers Module
    • Motivation
    • How to use
  • Foundations Module
    • Motivation and How to use
    • Actions
      • Local action traits
      • Extension action traits
      • Integration action traits
    • States
    • Utilities
      • Stores
      • Handlers and Services
        • Logging Service
  • Plugin
    • Main Plugin Instance
    • Plugin Components
  • Hierarchies
  • Helpers
  • Utilities Module
    • Motivation and How to use
    • Hooks Service
      • Scoped Handler
    • Shortcodes Service
    • Templating Service
    • Assets Service
      • Scripts Handler
      • Styles Handler
    • CRON Events Service
      • Action Scheduler Handler
    • Admin Notices Service
    • Dependencies Service
    • Validation Service
  • Core Module
    • Motivation and How to use
    • Plugin Tree
      • Plugin Root
      • Plugin Functionality
    • Plugin Components
      • Internationalization
      • Installation / Upgrade / Uninstallation
  • Settings Module
    • Motivation and How to use
    • Settings Service
      • WordPress Handler
      • MetaBox Handler
      • ACF Handler
    • Validated Settings
  • WooCommerce Module
    • Motivation and How to use
    • Extended WC Logger
    • WC Settings Handler
Powered by GitBook
On this page

Was this helpful?

  1. Utilities Module

Validation Service

PreviousDependencies ServiceNextMotivation and How to use

Last updated 4 years ago

Was this helpful?

The validation service is again with no . Its purpose is to standardize validating a value against a given type and a known default before using it in your code. It provides these public methods:

  • validate_value which is just a central hub for calling the other methods

  • validate_boolean_value for turning a value into a boolean or returning the default

  • validate_integer_value for turning a value into an integer or returning the default

  • validate_float_value for turning a value into a float or returning the default

  • validate_callback_value for checking whether a value is a valid callback or returning the default

  • validate_supported_value for checking whether a value is part of a supported list of values or returning the default

As you're probably expecting by now, all of these methods simply pass on the parameters to a given handler. The handler is free to decide what to do with those values -- the only non-negotiable aspect of this all is the return type of the validation operation. A boolean validation must return a boolean value.

There is just one type of handler pre-packaged with the module and that is the so-called . Basically this handler expects to be provided with a PSR-11-compatible container that contains exactly two 2 keys: defaults and options. Both keys should store an array. The former array is used for returning the default values and the latter for checking for supported options (for the supported value validation). The actual type validation is performed using the validation helpers from .

If you need a different logic, you may use your own custom handler that implements the interface.

a multi-handler service
action methods
container validation handler
the Helpers Module
ValidationHandlerInterface