Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/vendors/Textpattern/Validator/Constraint.php - 118 lines - 2418 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * https://textpattern.com/
   6   *
   7   * Copyright (C) 2020 The Textpattern Development Team
   8   *
   9   * This file is part of Textpattern.
  10   *
  11   * Textpattern is free software; you can redistribute it and/or
  12   * modify it under the terms of the GNU General Public License
  13   * as published by the Free Software Foundation, version 2.
  14   *
  15   * Textpattern is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
  22   */
  23  
  24  namespace Textpattern\Validator;
  25  
  26  /**
  27   * Constraint.
  28   *
  29   * Defines a single validation rule.
  30   *
  31   * @since   4.6.0
  32   * @package Validator
  33   */
  34  
  35  class Constraint
  36  {
  37      /**
  38       * The value to be validated.
  39       *
  40       * @var mixed
  41       */
  42  
  43      protected $value;
  44  
  45      /**
  46       * An array of options.
  47       *
  48       * @var array
  49       */
  50  
  51      protected $options;
  52  
  53      /**
  54       * Constructs a constraint.
  55       *
  56       * @param mixed $value The validee
  57       * @param array $options Key/value pairs of class-specific options
  58       */
  59  
  60      public function __construct($value, $options = array())
  61      {
  62          if (empty($options['message'])) {
  63              $options['message'] = 'undefined_constraint_violation';
  64          }
  65  
  66          $this->value = $value;
  67          $this->options = $options;
  68      }
  69  
  70      /**
  71       * Sets validee's value.
  72       *
  73       * @param $value mixed Validee
  74       */
  75  
  76      public function setValue($value)
  77      {
  78          $this->value = $value;
  79      }
  80  
  81      /**
  82       * Sets options.
  83       *
  84       * @param $options Scalar or array of options
  85       * @param null $key Key for scalar option
  86       */
  87  
  88      public function setOptions($options, $key = null)
  89      {
  90          if ($key === null) {
  91              $this->options = $options;
  92          } else {
  93              $this->options[$key] = $options;
  94          }
  95      }
  96  
  97      /**
  98       * Validate a given value against this constraint.
  99       *
 100       * @return bool If TRUE, the value obeys constraint
 101       */
 102  
 103      public function validate()
 104      {
 105          return true;
 106      }
 107  
 108      /**
 109       * Gets a message.
 110       *
 111       * @return string
 112       */
 113  
 114      public function getMessage()
 115      {
 116          return $this->options['message'];
 117      }
 118  }

title

Description

title

Description

title

Description

title

title

Body