HEX
Server: Apache/2
System: Linux s01 6.1.0-34-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.135-1 (2025-04-25) x86_64
User: beestg (1003)
PHP: 8.3.25
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/beestg/public_html/wp-content/plugins/code-snippets/php/cloud/class-cloud-link.php
<?php

namespace Code_Snippets\Cloud;

use Code_Snippets\Data_Item;

/**
 * A connection between a local snippet and remote cloud snippet.
 *
 * @package Code_Snippets
 *
 * @property integer $local_id         ID of local snippet as stored in WordPress database, if applicable.
 * @property integer $cloud_id         ID of remote snippet on cloud platform, if applicable.
 * @property boolean $is_owner         Ownership status of remote snippet on cloud platform.
 * @property boolean $in_codevault     Whether the remote snippet is stored in the users' codevault.
 * @property boolean $update_available If synchronised, whether there is an update available on the cloud platform.
 */
class Cloud_Link extends Data_Item {

	/**
	 * Constructor function
	 *
	 * @param array<string, mixed>|object $data Initial data fields.
	 */
	public function __construct( $data = null ) {
		parent::__construct(
			[
				'local_id'         => 0,
				'cloud_id'         => 0,
				'is_owner'         => false,
				'in_codevault'     => false,
				'update_available' => false,
			],
			$data
		);
	}

	/**
	 * Prepare a value before it is stored.
	 *
	 * @param mixed  $value Value to prepare.
	 * @param string $field Field name.
	 *
	 * @return mixed Value in the correct format.
	 */
	protected function prepare_field( $value, string $field ) {
		switch ( $field ) {
			case 'local_id':
			case 'remote_id':
				return absint( $value );

			case 'is_owner':
			case 'in_codevault':
			case 'update_available':
				return is_bool( $value ) ? $value : (bool) $value;

			default:
				return $value;
		}
	}
}