8889841cEmail.php000064400000000603150514541070006305 0ustar00description = $description; return $this; } /** * @since 2.22.0 */ public function getDescription(): string { return $this->description; } } Contracts/Collection.php000064400000003361150514541070011315 0ustar00name = $name; $this->__visibilityConditionsConstruct(); } /** * @inheritDoc */ public function getNodeType(): string { return 'group'; } /** * @since 2.12.0 * * @param $name * * @return static */ public static function make($name) { return new static($name); } /** * Gives th ability to fluently "tap" a specific node within the group. This is useful when fluently calling methods * on the group, and making a change to a specific node without breaking the fluency. * * @since 2.22.0 * * @return $this */ public function tapNode(string $name, callable $callback) { $callback($this->getNodeByName($name)); return $this; } } Actions/CreateValidatorFromForm.php000064400000001244150514541070013401 0ustar00getFields() as $field) { $rules[$field->getName()] = $field->getValidationRules(); if (method_exists($field, 'getLabel')) { $labels[$field->getName()] = $field->getLabel(); } } return new Validator($rules, $values, $labels); } } Element.php000064400000002172150514541070006652 0ustar00name = $name; $this->__visibilityConditionsConstruct(); } /** * @inheritDoc */ public function getNodeType(): string { return 'element'; } /** * Create a named block. * * @since 2.12.0 * * @param string $name * * @return static */ public static function make($name) { return new static($name); } } Text.php000064400000000543150514541070006205 0ustar00emailTag = $emailTag; return $this; } /** * @since 2.28.0 add types * * @return string|null */ public function getEmailTag() { return $this->emailTag; } } Concerns/WalkNodes.php000064400000001764150514541070010730 0ustar00walkCollection($this, $callback); } /** * @param Collection $collection * @param callable $callback * * @return void */ public function walkCollection(Collection $collection, callable $callback) { foreach ($collection->all() as $node) { $callback($node); if ($node instanceof Collection) { $this->walkCollection($node, $callback); } } } /** * @param callable $callback * * @return void */ public function walkFields(callable $callback) { foreach ($this->getFields() as $field) { $callback($field); } } } Concerns/MoveNode.php000064400000000470150514541070010546 0ustar00move( $collection->getNodeByName($name) ); return $proxy; } } Concerns/HasLabel.php000064400000000660150514541070010506 0ustar00label = $label; return $this; } /** * @since 2.24.0 add types * * @return string|null */ public function getLabel() { return $this->label; } } Concerns/Macroable.php000064400000002705150514541070010722 0ustar00bindTo($this, static::class); } return $macro(...$parameters); } } Concerns/HasType.php000064400000000306150514541070010405 0ustar00helpText = $helpText; return $this; } public function getHelpText() { return $this->helpText; } } Concerns/AllowMultiple.php000064400000001133150514541070011621 0ustar00allowMultiple = $allowMultiple; return $this; } /** * Access whether or not the field allows multiple. * * @return bool */ public function getAllowMultiple() { return $this->allowMultiple; } } Concerns/HasMaxLength.php000064400000001734150514541070011361 0ustar00hasRule('max') ) { /** @var Max $rule */ $rule = $this->getRule('max'); $rule->size($maxLength); } $this->rules("max:$maxLength"); return $this; } /** * Get the value’s maximum length. * * @since 2.24.0 update to use the new validation system * @since 2.14.0 * * @return int|null */ public function getMaxLength() { if ( !$this->hasRule('max') ) { return null; } return $this->getRule('max')->getSize(); } } Concerns/MoveNodeProxy.php000064400000002402150514541070011605 0ustar00collection = $collection; } /** * @param Node $node */ public function move($node) { $this->targetNode = $node; } /** * @param string $name The name of the node after which the target node should be inserted. */ public function after($name) { $this->collection->remove($this->targetNode->getName()); $this->collection->insertAfter($name, $this->targetNode); } /** * @param string $name The name of the node before which the target node should be inserted. */ public function before($name) { $this->collection->remove($this->targetNode->getName()); $this->collection->insertBefore($name, $this->targetNode); } } Concerns/TapNode.php000064400000000502150514541070010360 0ustar00visibilityConditions = new SimpleConditionSet(); } /** * Get the visibility conditions. * * @since 2.27.3 update to use SimpleConditionSet * @since 2.13.0 * * @return Condition[] */ public function getVisibilityConditions(): array { return $this->visibilityConditions->getConditions(); } /** * @since 2.27.3 replace with native condition set method * @since 2.16.0 */ public function hasVisibilityConditions(): bool { return $this->visibilityConditions->hasConditions(); } /** * @since 2.27.3 */ public function passesVisibilityConditions(array $values): bool { return $this->visibilityConditions->passes($values); } /** * @since 2.27.3 */ public function failsVisibilityConditions(array $values): bool { return $this->visibilityConditions->fails($values); } /** * Set a condition for showing the node. * * @since 2.27.3 update to use SimpleConditionSet * @since 2.13.0 */ public function showIf(string $field, string $operator, $value, string $boolean = 'and'): self { if ($boolean === 'and') { $this->visibilityConditions->and($field, $operator, $value); } else { $this->visibilityConditions->or($field, $operator, $value); } $this->updateValidationRules(); return $this; } /** * Add an "or" visibility condition, useful when chained for readability. * * @since 2.27.3 */ public function orShowIf(string $field, string $operator, $value): self { $this->visibilityConditions->or($field, $operator, $value); $this->updateValidationRules(); return $this; } /** * Add an "and" visibility condition, useful when chained for readability. * * @since 2.27.3 */ public function andShowIf(string $field, string $operator, $value): self { $this->visibilityConditions->and($field, $operator, $value); $this->updateValidationRules(); return $this; } /** * Set multiple conditions for showing the node. * * @since 2.27.3 update to use FieldCondition * @since 2.13.0 * * @param FieldCondition|array ...$conditions */ public function showWhen(...$conditions): self { foreach ($conditions as $condition) { $this->visibilityConditions->append($this->normalizeCondition($condition)); } $this->updateValidationRules(); return $this; } /** * Updates the validation rules to include the visibility conditions. This prevents the node from being validated * when the conditions are not met. * * This also only adds the validation rule if the node has validation rules. * * @since 2.27.3 */ protected function updateValidationRules() { if (method_exists($this, 'replaceOrPrependRule')) { $this->replaceOrPrependRule(ExcludeUnless::id(), new ExcludeUnless($this->visibilityConditions)); } } /** * Normalize the condition if in array format. * * @since 2.27.3 update to use FieldCondition * @since 2.13.0 * * @param FieldCondition|array $condition * * @throws InvalidArgumentException */ protected function normalizeCondition($condition): FieldCondition { if ($condition instanceof FieldCondition) { return $condition; } if (is_array($condition)) { return new FieldCondition(...$condition); } throw new InvalidArgumentException('Parameter $condition must be a FieldCondition or an array.'); } } Concerns/NameCollision.php000064400000001506150514541070011567 0ustar00checkNameCollision($node); if ($node instanceof Collection) { $node->walk([$this, 'checkNameCollision']); } } /** * @since 2.10.2 * * @throws NameCollisionException */ public function checkNameCollision(Node $node) { if ($this->getNodeByName($node->getName())) { throw new NameCollisionException($node->getName()); } } } Concerns/ShowInReceipt.php000064400000000760150514541070011557 0ustar00showInReceipt = $showInReceipt; return $this; } /** * @since 2.10.2 */ public function shouldShowInReceipt(): bool { return $this->showInReceipt; } } Concerns/HasDefaultValue.php000064400000001141150514541070012043 0ustar00defaultValue = $defaultValue; return $this; } /** * @return string|array */ public function getDefaultValue() { return $this->defaultValue; } /** * @return string|array */ public function getSelected() { return $this->getDefaultValue(); } } Concerns/HasNodes.php000064400000003420150514541070010534 0ustar00nodes as $index => $node) { if ($node->getName() === $name) { return $index; } } return null; } /** * @inheritdoc * * @return Node|null */ public function getNodeByName(string $name) { foreach ($this->nodes as $node) { if ($node->getName() === $name) { return $node; } if ($node instanceof Collection) { $nestedNode = $node->getNodeByName($name); if ($nestedNode !== null) { return $nestedNode; } } } return null; } /** * @inheritdoc */ public function all(): array { return $this->nodes; } /** * @inheritdoc * * @return Field[] */ public function getFields(): array { $fields = []; foreach ($this->nodes as $node) { if ($node instanceof Field) { $fields[] = $node; } elseif ($node instanceof Collection) { $nestedFields = $node->getFields(); foreach($nestedFields as $field) { $fields[] = $field; } } } return $fields; } /** * @inheritdoc */ public function count(): int { return count($this->nodes); } } Concerns/HasPlaceholder.php000064400000001032150514541070011703 0ustar00placeholder = $placeholder; return $this; } /** * Get the placeholder value. * * @return string */ public function getPlaceholder() { return $this->placeholder; } } Concerns/RemoveNode.php000064400000001177150514541070011102 0ustar00nodes as $index => $node) { if ($node->getName() === $name) { unset($this->nodes[$index]); return $this; } if ($node instanceof Collection) { return $node->remove($name); } } // Maybe need to throw an exception if no node is removed. return $this; } } Concerns/SerializeAsJson.php000064400000001642150514541070012101 0ustar00 $this->getNodeType(), 'type' => $this->getType(), 'name' => $this->getName(), ], // We (recursively) serialize all of the class’ properties and exclude the list provided. array_map( static function ($value) { if ($value instanceof JsonSerializable) { return $value->jsonSerialize(); } return $value; }, get_object_vars($this) ) ); } } Concerns/HasOptions.php000064400000004447150514541070011131 0ustar00options = []; // Loop through the options and transform them to the proper format. foreach ($options as $value) { if ($value instanceof Option) { // In this case, what is provided matches the proper format, so we can just append it. $this->options[] = $value; } elseif (is_array($value)) { // In this case, what has been provided in the value is an array with a value then a label. // This matches the constructor of `FieldOption`, so we can unpack it as arguments for a new instance. $this->options[] = new Option(...$value); } else { // In this case, we just have a value which is the bare minimum required for a `FieldOption`. $this->options[] = new Option($value); } } return $this; } /** * Access the options * * @return Option[] */ public function getOptions() { return $this->options; } /** * Check whether options exist * * @since 2.15.0 * * @return bool */ public function hasOptions() { return (bool)count($this->options); } /** * Walk through the options * * @since 2.12.0 * * @param callable $callback * * @return void */ public function walkOptions(callable $callback) { foreach ($this->options as $option) { // Call the callback for each option. if ($callback($option) === false) { // Returning false breaks the loop. break; } } } } Concerns/StoreAsMeta.php000064400000001111150514541070011212 0ustar00storeAsDonorMeta = $storeAsDonorMeta; return $this; } /** * @since 2.28.0 added types * @since 2.10.2 */ public function shouldStoreAsDonorMeta(): bool { return $this->storeAsDonorMeta; } } Concerns/ShowInAdmin.php000064400000000740150514541070011212 0ustar00showInAdmin = $showInAdmin; return $this; } /** * @since 2.27.3 */ public function shouldShowInAdmin(): bool { return $this->showInAdmin; } } Concerns/HasName.php000064400000000362150514541070010346 0ustar00name; } } Concerns/IsReadOnly.php000064400000000664150514541070011050 0ustar00readOnly = $readOnly; return $this; } /** * @return bool */ public function isReadOnly() { return $this->readOnly; } } Concerns/IsRequired.php000064400000001676150514541070011117 0ustar00validationRules->rules('required'); } else { $this->validationRules->removeRuleWithId('required'); } return $this; } /** * Returns whether the field is required or not. * * @since 2.24.0 switch to new validation system */ public function isRequired(): bool { return $this->hasRule('required'); } /** * @deprecated Use the Validator to generate errors */ public function getRequiredError(): array { return [ 'error_id' => $this->name, 'error_message' => __('Please enter a value for ' . $this->name, 'give'), ]; } } Concerns/InsertNode.php000064400000006463150514541070011114 0ustar00checkNameCollisionDeep($node); $this->insertAfterRecursive($siblingName, $node); return $this; } /** * @since 2.10.2 * * @return void * @throws ReferenceNodeNotFoundException|NameCollisionException */ protected function insertAfterRecursive(string $siblingName, Node $node) { $siblingIndex = $this->getNodeIndexByName($siblingName); if (null !== $siblingIndex) { $this->insert( $node, $siblingIndex + 1 ); return; } if ($this->nodes) { foreach ($this->nodes as $childNode) { if ($childNode instanceof Collection) { $childNode->insertAfter($siblingName, $node); } } return; } throw new ReferenceNodeNotFoundException($siblingName); } /** * @inheritDoc * * @since 2.10.2 * * @throws ReferenceNodeNotFoundException|NameCollisionException */ public function insertBefore(string $siblingName, Node $node): self { $this->checkNameCollisionDeep($node); $this->insertBeforeRecursive($siblingName, $node); return $this; } /** * @since 2.10.2 * * @return void * @throws ReferenceNodeNotFoundException|NameCollisionException */ protected function insertBeforeRecursive(string $siblingName, Node $node) { $siblingIndex = $this->getNodeIndexByName($siblingName); if (null !== $siblingIndex) { $this->insert( $node, $siblingIndex - 1 ); return; } if ($this->nodes) { foreach ($this->nodes as $childNode) { if ($childNode instanceof Collection) { $childNode->insertBefore($siblingName, $node); } } return; } throw new ReferenceNodeNotFoundException($siblingName); } /** * @since 2.24.0 Make index optional to avoid rebuilding array when appending * @since 2.10.2 * * @param int|null $index appends to end if null * * @throws NameCollisionException */ protected function insert(Node $node, int $index = null) { $this->checkNameCollisionDeep($node); if ($index === null) { $this->nodes[] = $node; } else { array_splice($this->nodes, $index, 0, [$node]); } } /** * @inheritdoc * * @since 2.10.2 * * @throws NameCollisionException */ public function append(Node ...$nodes): self { foreach ($nodes as $node) { $this->insert($node); } return $this; } } Concerns/HasMinLength.php000064400000001675150514541070011363 0ustar00hasRule('min') ) { /** @var Min $rule */ $rule = $this->getRule('min'); $rule->size($minLength); } $this->rules("min:$minLength"); return $this; } /** * Get the value’s minimum length. * * @since 2.24.0 update to use the new validation system * @since 2.14.0 * * @return int|null */ public function getMinLength() { $rule = $this->getRule('min'); return $rule instanceof Min ? $rule->getSize() : null; } } Hidden.php000064400000000271150514541070006452 0ustar00defaultValue((bool)$default); return $this; } /** * Returns whether the checkbox is checked by default * * @since 2.12.0 * * @return bool */ public function isChecked() { return (bool)$this->defaultValue; } } Exceptions/EmptyNameException.php000064400000000561150514541070013160 0ustar00name = $name; } public function getNodeType(): string { return 'group'; } /** * @inheritDoc * * @param Section[] $nodes * * @throws TypeNotSupported */ public function append(Node ...$nodes) { foreach ($nodes as $node) { if ( ! $node instanceof Section) { throw new TypeNotSupported($node->getType()); } $this->insert($node); } return $this; } } Phone.php000064400000000543150514541070006332 0ustar00name = $name; $this->__validationRulesConstruct(); $this->__visibilityConditionsConstruct(); } /** * @inheritDoc */ public function getNodeType(): string { return 'field'; } /** * Create a named field. * * @since 2.12.0 * * @return static * @throws EmptyNameException */ public static function make(string $name): self { if (!$name) { throw new EmptyNameException(); } return new static($name); } } Checkbox.php000064400000003445150514541070007013 0ustar00value = $value; $this->defaultValue = $this->checked ? $value : null; return $this; } /** * @since 2.28.0 */ public function getValue() { return $this->value; } /** * Since the default value needs to reflect the value of the checkbox, this method is not supported. * * @since 2.28.0 */ public function defaultValue($defaultValue) { throw new RuntimeException( 'Do not set the default value. Instead, set the value and use the checked() method.' ); } /** * Sets the checkbox as checked by default * * The default value is also set because the getDefaultMethod() method is not called during serialization. * * @since 2.28.0 */ public function checked(bool $checked = true): self { $this->checked = $checked; $this->defaultValue = $this->checked ? $this->value : null; return $this; } /** * @since 2.28.0 */ public function isChecked(): bool { return $this->checked; } } File.php000064400000003623150514541070006142 0ustar00hasRule('max')) { /** @var Max $rule */ $rule = $this->getRule('max'); $rule->size($maxSize); } $this->rules("max:$maxSize"); return $this; } /** * Access the maximum file size. */ public function getMaxSize(): int { if (!$this->hasRule('max')) { return wp_max_upload_size(); } return $this->getRule('max')->getSize(); } /** * Set the allowed file types. * * @param string[] $allowedTypes * * @return $this */ public function allowedTypes(array $allowedTypes) { if ($this->hasRule('allowedTypes')) { /** @var AllowedTypes $rule */ $rule = $this->getRule('allowedTypes'); $rule->setAllowedtypes($allowedTypes); } $this->rules('allowedTypes:' . implode(',', $allowedTypes)); return $this; } /** * Access the allowed file types. * * @return string[] */ public function getAllowedTypes() { if (!$this->hasRule('allowedTypes')) { return get_allowed_mime_types(); } return $this->getRule('allowedTypes')->getAllowedTypes(); } } Option.php000064400000002105150514541070006525 0ustar00value = $value; $this->label = $label; } /** * Create a new option. * * @since 2.12.0 * * @return static */ public static function make(...$args) { return new static(...$args); } /** * Access the value * * @since 2.12.0 * * @return string */ public function getValue() { return $this->value; } /** * {@inheritdoc} */ public function jsonSerialize() { return [ 'value' => $this->getValue(), 'label' => $this->getLabel(), ]; } } Types.php000064400000001722150514541070006365 0ustar00getConstants()); } } Date.php000064400000000364150514541070006137 0ustar00html = $html; return $this; } /** * Get the HTML for the element. * * @since 2.28.0 added types * @since 2.12.2 */ public function getHtml(): string { return $this->html; } }