PluginProbe
DecaLog / 3.0.2
DecaLog v3.0.2
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / features / class-wordpresshandler.php

class-wordpresshandler.php in DecaLog 3.0.2, at includes/features/class-wordpresshandler.php

133 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress handler utility
4 *
5 * Handles all features of WordPress handler.
6 *
7 * @package Features
8 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
9 * @since 1.0.0
10 */
11
12 namespace Decalog\Plugin\Feature;
13
14 use Decalog\Storage\AbstractStorage;
15 use Decalog\System\Database;
16 use Decalog\System\Http;
17 use Decalog\Storage\DBStorage;
18 use Decalog\Storage\APCuStorage;
19
20 /**
21 * Define the WordPress handler functionality.
22 *
23 * Handles all features of WordPress handler.
24 *
25 * @package Features
26 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
27 * @since 1.0.0
28 */
29 class WordpressHandler {
30
31 /**
32 * The logger definition.
33 *
34 * @since 1.0.0
35 * @var array $logger The logger definition.
36 */
37 private $logger = [];
38
39 /**
40 * The bucket name.
41 *
42 * @since 1.0.0
43 * @var string $bucket_name The bucket name.
44 */
45 private $bucket_name = '';
46
47 /**
48 * The storage engine.
49 *
50 * @since 3.0.0
51 * @var \Decalog\Storage\AbstractStorage $storage The storage engine.
52 */
53 private $storage = null;
54
55 /**
56 * Initialize the class and set its properties.
57 *
58 * @param array $logger The logger definition.
59 * @since 1.0.0
60 */
61 public function __construct( $logger = [] ) {
62 if ( [] !== $logger ) {
63 $this->set_logger( $logger );
64 }
65 }
66
67 /**
68 * Set the internal logger.
69 *
70 * @param array $logger The logger definition.
71 * @since 1.0.0
72 */
73 public function set_logger( $logger ) {
74 $this->logger = $logger;
75 $this->bucket_name = 'decalog_' . str_replace( '-', '', $logger['uuid'] );
76 switch ( $logger['configuration']['constant-storage'] ) {
77 case 'apcu':
78 $this->storage = new APCuStorage( $this->bucket_name );
79 break;
80 default:
81 $this->storage = new DBStorage( $this->bucket_name );
82 }
83 }
84
85 /**
86 * Initialize the logger.
87 *
88 * @since 1.0.0
89 */
90 public function initialize() {
91 $this->storage->initialize();
92 }
93
94 /**
95 * Update the logger.
96 *
97 * @param string $from The version from which the plugin is updated.
98 * @since 1.0.0
99 */
100 public function update( $from ) {
101 $this->storage->update( $from );
102 }
103
104 /**
105 * Finalize the logger.
106 *
107 * @since 1.0.0
108 */
109 public function finalize() {
110 $this->storage->finalize();
111 }
112
113 /**
114 * Force bucket purge.
115 *
116 * @since 2.0.0
117 */
118 public function force_purge() {
119 $this->storage->force_purge();
120 }
121
122 /**
123 * Rotate and purge.
124 *
125 * @return integer The number of deleted records.
126 * @since 1.0.0
127 */
128 public function cron_clean() {
129 $this->storage->cron_clean( $this->logger );
130 }
131
132 }
133