edoc automate Guide
Breadcrumbs

API for validators in edoc automate

You can configure a validation function (validator) for each action. Using the API, you can extend the default validation functions in the Validation section of an action with new validators. You add your own validation function in actions as a separate app plug-in.

Namespace for validators

The default validators and plug-in validators use the same namespace.

PHP
namespace edoc\appserver\app\validators;

Base class for validators

Validators must inherit from the AbstractValidator class. Plug-ins that do not inherit from AbstractValidator cannot be loaded by edoc automate.

PHP
<?php

abstract class AbstractValidator
{
  
    abstract protected function exec($value): bool;
    abstract protected function init(): void;
    
    /* adds a configuration-parameter */ 
    protected function addParameter($name, $type, $defaultValue = '');
    
    /* returns the configured value for the given parameter name */
    protected function param($name);
    
    /* returns the configured or currently set message */
    public function message(): string
    
    /* overwrites the configured message */
    protected function setMessage($message): void
    
    /* returns the id from the currently validated component */
    protected function currentComponentId(): string
}

Add your own app validators

If you cannot perform certain checks when validating components with the default validators, you must create a new plug-in in the app folder ./<app>/plugins/validators/ via WebDAV, for example.

You can easily create a new plug-in via WebDAV in the browser using a form.

Here's how

  1. Create a new folder in the ./<app>/plugins/validators/ folder (e.g. Email). The name of the folder must reflect the name of the action.

  2. Create a file in the folder with the same name and the extension .php (e.g. Email.php).

  3. Open the file with any text editor.

  4. Add the following content to the file:

    PHP
    <?php
    
    namespace edoc\appserver\app\validators;
    
    use edoc\appserver\app\AbstractValidator;
    
    class Email extends AbstractValidator
    {
      protected function init(): void
      {
      }
      protected function exec($value): bool
      {
        return filter_var($value, FILTER_VALIDATE_EMAIL);
      }
    }
    
  5. Save the file with the correct encoding: UTF-8 without BOM.