PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / class-db.php

class-db.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/class-db.php

73 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles database operations.
4 *
5 * @package WP_Defender
6 */
7
8 namespace WP_Defender;
9
10 use Calotes\DB\Mapper;
11 use Calotes\Base\Model;
12 use ReflectionException;
13
14 /**
15 * Contains methods for saving the current instance, getting the ORM, and retrieving the table name.
16 */
17 class DB extends Model {
18
19 /**
20 * Constructor for the class.
21 * Initializes the object by parsing annotations.
22 *
23 * @return void
24 */
25 public function __construct() {
26 $this->parse_annotations();
27 }
28
29 /**
30 * Save the current instance.
31 *
32 * @return false|int
33 */
34 public function save(): bool|int {
35 try {
36 return self::get_orm()->save( $this );
37 } catch ( \Throwable $e ) {
38 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
39 $this->log(
40 sprintf(
41 'Failed to save %s: %s in %s:%d',
42 static::class,
43 $e->getMessage(),
44 $e->getFile(),
45 $e->getLine()
46 ),
47 'db-save-error.log'
48 );
49 }
50
51 return false;
52 }
53 }
54
55 /**
56 * Retrieves the ORM instance from the dependency injection container.
57 *
58 * @return Mapper The ORM instance.
59 */
60 protected static function get_orm(): Mapper {
61 return wd_di()->get( Mapper::class );
62 }
63
64 /**
65 * Get table name.
66 *
67 * @return string
68 */
69 public function get_table(): string {
70 return $this->table;
71 }
72 }
73