PluginProbe
Code Snippets / 3.6.6
Code Snippets v3.6.6
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 / cloud / class-cloud-link.php

class-cloud-link.php in Code Snippets 3.6.6, at php/cloud/class-cloud-link.php

62 lines 1.6 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\Cloud;
4
5 use Code_Snippets\Data_Item;
6
7 /**
8 * A connection between a local snippet and remote cloud snippet.
9 *
10 * @package Code_Snippets
11 *
12 * @property integer $local_id ID of local snippet as stored in WordPress database, if applicable.
13 * @property integer $cloud_id ID of remote snippet on cloud platform, if applicable.
14 * @property boolean $is_owner Ownership status of remote snippet on cloud platform.
15 * @property boolean $in_codevault Whether the remote snippet is stored in the users' codevault.
16 * @property boolean $update_available If synchronised, whether there is an update available on the cloud platform.
17 */
18 class Cloud_Link extends Data_Item {
19
20 /**
21 * Constructor function
22 *
23 * @param array<string, mixed>|object $data Initial data fields.
24 */
25 public function __construct( $data = null ) {
26 parent::__construct(
27 [
28 'local_id' => 0,
29 'cloud_id' => 0,
30 'is_owner' => false,
31 'in_codevault' => false,
32 'update_available' => false,
33 ],
34 $data
35 );
36 }
37
38 /**
39 * Prepare a value before it is stored.
40 *
41 * @param mixed $value Value to prepare.
42 * @param string $field Field name.
43 *
44 * @return mixed Value in the correct format.
45 */
46 protected function prepare_field( $value, string $field ) {
47 switch ( $field ) {
48 case 'local_id':
49 case 'remote_id':
50 return absint( $value );
51
52 case 'is_owner':
53 case 'in_codevault':
54 case 'update_available':
55 return is_bool( $value ) ? $value : (bool) $value;
56
57 default:
58 return $value;
59 }
60 }
61 }
62