PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / Model / Cloud_Link.php

Cloud_Link.php in Code Snippets 3.10.0, at php/Model/Cloud_Link.php

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Model;
4
5 /**
6 * A connection between a local snippet and remote cloud snippet.
7 *
8 * @package Code_Snippets
9 *
10 * @property int $local_id ID of local snippet as stored in WordPress database, if applicable.
11 * @property int $cloud_id ID of remote snippet on cloud platform, if applicable.
12 * @property bool $is_owner Ownership status of remote snippet on cloud platform.
13 * @property bool $in_codevault Whether the remote snippet is stored in the users' codevault.
14 * @property bool $update_available If synchronised, whether there is an update available on the cloud platform.
15 */
16 class Cloud_Link extends Model {
17
18 /**
19 * List of default values provided for fields.
20 *
21 * @var array<string, mixed>
22 */
23 protected static array $default_values = [
24 'local_id' => 0,
25 'cloud_id' => 0,
26 'is_owner' => false,
27 'in_codevault' => false,
28 'update_available' => false,
29 ];
30
31 /**
32 * Prepare a value before it is stored.
33 *
34 * @param mixed $value Value to prepare.
35 * @param string $field Field name.
36 *
37 * @return mixed Value in the correct format.
38 */
39 protected function prepare_field( $value, string $field ) {
40 switch ( $field ) {
41 case 'local_id':
42 case 'remote_id':
43 return absint( $value );
44
45 case 'is_owner':
46 case 'in_codevault':
47 case 'update_available':
48 return is_bool( $value ) ? $value : (bool) $value;
49
50 default:
51 return $value;
52 }
53 }
54 }
55