PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / 2.0.6
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF v2.0.6
2.0.6 2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / includes / classes / models / class-rio-base-active-record.php
robin-image-optimizer / includes / classes / models Last commit date
class-rio-attachment-extra-data.php 7 months ago class-rio-base-active-record.php 7 months ago class-rio-base-extra-data.php 7 months ago class-rio-base-helper.php 7 months ago class-rio-base-object.php 7 months ago class-rio-process-queue-table.php 1 month ago class-rio-server-smushit-extra-data.php 7 months ago class.webp-extra-data.php 7 months ago
class-rio-base-active-record.php
96 lines
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Class WRIO_Base_Model used as a base class for any database related model.
10 *
11 * Usage example:
12 * ```php
13 * Custom extends RIO_Base_Model {
14 * public $prop;
15 * }
16 *
17 * $model = new Custom(array('prop' => 123)); // or ['prop' => 123]
18 * $model->save();
19 * ```
20 */
21 class RIO_Base_Active_Record extends RIO_Base_Object {
22
23 /**
24 * Get table name.
25 *
26 * @return string|null
27 */
28 public static function table_name() {
29 return null;
30 }
31
32 /**
33 * @todo override with activerecord impl
34 *
35 * @param string $name
36 * @param mixed $value
37 *
38 * @throws Exception
39 */
40 public function __set( $name, $value ) {
41 if ( property_exists( $this, $name ) ) {
42 $this->$name = $value;
43 }
44 }
45
46
47 /**
48 * Check whether table has SQL schema or not.
49 *
50 * @return bool
51 */
52 public static function has_table_schema() {
53 $schema = static::get_table_schema();
54
55 return ! empty( $schema );
56 }
57
58 /**
59 * Check whether table has indexes defined.
60 *
61 * Notice: method would check whether model has schema defined first and then indexes.
62 *
63 * @return bool
64 */
65 public static function has_table_indexes() {
66
67 if ( ! static::has_table_schema() ) {
68 return false;
69 }
70
71 $indexes = static::get_table_indexes();
72
73 return ! empty( $indexes );
74 }
75
76 /**
77 * Get table SQL schema structure.
78 *
79 * @return string|null String when model has database table, null otherwise.
80 */
81 public static function get_table_schema() {
82 return null;
83 }
84
85 /**
86 * Get list of indexes.
87 *
88 * None associative list of
89 *
90 * @return array Empty array returned in case when no indexes exist on table.
91 */
92 public static function get_table_indexes() {
93 return [];
94 }
95 }
96