HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/onlineshop/wp-content/plugins/mailpoet/lib-3rd-party/Sudzy/Engine.php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

namespace MailPoetVendor\Sudzy;

if (!defined('ABSPATH')) exit;


/**
 * Singleton valdation engine
 **/
class Engine
{
    /**
    * Validation methods are stored here so they can easily be overwritten
    */
  protected $_checks;

  public function __construct() {
      $this->_checks = [
          'required'  => [$this, '_required'],
          'minLength' => [$this, '_minLength'],
          'maxLength' => [$this, '_maxLength'],
          'isEmail'   => [$this, '_isEmail'],
          'isInteger'   => [$this, '_isInteger'],
          'isNumeric'   => [$this, '_isNumeric'],
      ];
  }

  public function __call($name, $args) {
      if (!isset($this->_checks[$name]))
          throw new \InvalidArgumentException("{$name} is not a valid validation function.");

      $val = array_shift($args);
      $args = array_shift($args);

      return call_user_func($this->_checks[$name], $val, $args);
  }

  public function executeOne($check, $val, $params=[]) {
    $callback = [$this, $check];
    if (is_callable($callback)) {
      return call_user_func($callback, $val, $params);
    }
  }

    /**
     * @param string $label label used to call function
     * @param Callable $function function with params (value, additional params as array)
     * @throws \Exception
     */
  public function addValidator($label, $function) {
      if (isset($this->_checks[$label])) throw new \Exception();
      $this->setValidator($label, $function);
  }

  public function setValidator($label, $function) {
      $this->_checks[$label] = $function;
  }

  public function removeValidator($label) {
      unset($this->_checks[$label]);
  }

    /**
    * @return array<int, int|string> The list of usable validator methods
    */
  public function getValidators() {
      return array_keys($this->_checks);
  }

    ///// Validator methods
  protected function _isEmail($val, $params) {
      return false !== filter_var($val, FILTER_VALIDATE_EMAIL);
  }

  protected function _isInteger($val, $params) {
      if (!is_numeric($val)) return false;
      return intval($val) == $val;
  }

  protected function _isNumeric($val, $params) {
      return is_numeric($val);
  }

  protected function _minLength($val, $params) {
      $len = array_shift($params);
      return strlen($val) >= $len;
  }

  protected function _maxLength($val, $params) {
      $len = array_shift($params);
      return strlen($val) <= $len;
  }

  protected function _required($val, $params=[]) {
      return !(($val === null) || ('' === trim($val)));
  }
}