[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_scheduler 6 * 7 * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Scheduler\Administrator\Rule; 12 13 use Joomla\CMS\Form\Form; 14 use Joomla\CMS\Form\FormRule; 15 use Joomla\CMS\Form\Rule\OptionsRule; 16 use Joomla\Registry\Registry; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * The ExecutionRulesRule Class. 24 * Validates execution rules, with input for other fields as context. 25 * 26 * @since 4.1.0 27 */ 28 class ExecutionRulesRule extends FormRule 29 { 30 /** 31 * @var string RULE_TYPE_FIELD The field containing the rule type to test against 32 * @since 4.1.0 33 */ 34 private const RULE_TYPE_FIELD = "execution_rules.rule-type"; 35 36 /** 37 * @var string CUSTOM_RULE_GROUP The field group containing custom execution rules 38 * @since 4.1.0 39 */ 40 private const CUSTOM_RULE_GROUP = "execution_rules.custom"; 41 42 /** 43 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form 44 * field object. 45 * @param mixed $value The form field value to validate. 46 * @param ?string $group The field name group control value. This acts as an array container for the 47 * field. For example if the field has `name="foo"` and the group value is set 48 * to "bar" then the full field name would end up being "bar[foo]". 49 * @param ?Registry $input An optional Registry object with the entire data set to validate against 50 * the entire form. 51 * @param ?Form $form The form object for which the field is being tested. 52 * 53 * @return boolean 54 * 55 * @since 4.1.0 56 */ 57 public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null): bool 58 { 59 $fieldName = (string) $element['name']; 60 $ruleType = $input->get(self::RULE_TYPE_FIELD); 61 62 if ($ruleType === $fieldName || ($ruleType === 'custom' && $group === self::CUSTOM_RULE_GROUP)) { 63 return $this->validateField($element, $value, $group, $form); 64 } 65 66 return true; 67 } 68 69 /** 70 * @param \SimpleXMLElement $element The SimpleXMLElement for the field. 71 * @param mixed $value The field value. 72 * @param ?string $group The form field group the element belongs to. 73 * @param Form|null $form The Form object against which the field is tested/ 74 * 75 * @return boolean True if field is valid 76 * 77 * @since 4.1.0 78 */ 79 private function validateField(\SimpleXMLElement $element, $value, ?string $group = null, ?Form $form = null): bool 80 { 81 $elementType = (string) $element['type']; 82 83 // If element is of cron type, we test against options and return 84 if ($elementType === 'cron') { 85 return (new OptionsRule())->test($element, $value, $group, null, $form); 86 } 87 88 // Test for a positive integer value and return 89 return filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |