HEX
Server: Apache/2.4.62 (Debian)
System: Linux plxsite 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64
User: root (0)
PHP: 8.1.30
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/admin-menu-editor/customizables/Schemas/JsonValue.php
<?php

namespace YahnisElsts\AdminMenuEditor\Customizable\Schemas;

class JsonValue extends Schema {
	/**
	 * @var Schema
	 */
	protected $parsedValueSchema;

	public function __construct(Schema $parsedValueSchema, $label = null) {
		parent::__construct($label);
		$this->parsedValueSchema = $parsedValueSchema;
	}

	public function parse($value, $errors = null, $stopOnFirstError = false) {
		$value = $this->checkForNull($value, $errors);
		if ( ($value === null) || is_wp_error($value) ) {
			return $value;
		}

		if ( !is_string($value) ) {
			return self::addError($errors, 'not_string', 'Value must be a string');
		}

		$parsedValue = json_decode($value, true);
		if ( ($parsedValue === null) && (json_last_error() !== JSON_ERROR_NONE) ) {
			return self::addError($errors, 'invalid_json', 'Invalid JSON: ' . json_last_error_msg());
		}

		return $this->parsedValueSchema->parse($parsedValue, $errors, $stopOnFirstError);
	}
}