PluginProbe
ManageWP Worker / 4.9.29
ManageWP Worker v4.9.29
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Configuration / Service.php

Service.php in ManageWP Worker 4.9.29, at src/MWP/Configuration/Service.php

77 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 /**
12 * Class MWP_Configuration_Service
13 * This class is service provider for configuration object.
14 * It include get/save operations, with singleton to lower database hits.
15 *
16 * @package src\MWP\Configuration
17 */
18 class MWP_Configuration_Service
19 {
20 /**
21 * @var MWP_Configuration_Conf
22 */
23 public static $configuration;
24
25 /**
26 * Returns configuration instance. This is singleton
27 *
28 * @return MWP_Configuration_Conf
29 */
30 public function getConfiguration()
31 {
32 if (!self::$configuration) {
33 /** @handled function fix */
34 $configuration = get_option("mwp_worker_configuration");
35 $path = realpath(dirname(__FILE__)."/../../../worker.json");
36 if (empty($configuration) && file_exists($path)) {
37 $json = file_get_contents($path);
38 $configuration = json_decode($json, true);
39 /** @handled function fix */
40 update_option("mwp_worker_configuration", $configuration);
41 }
42
43 self::$configuration = new MWP_Configuration_Conf($configuration);
44 }
45
46 return self::$configuration;
47 }
48
49 /**
50 * Reloads configuration from database, update internal singleton and returns reload object
51 *
52 * @return MWP_Configuration_Conf
53 */
54 public function reloadConfiguration()
55 {
56 /** @handled function fix */
57 self::$configuration = new MWP_Configuration_Conf(get_option("mwp_worker_configuration"));
58
59 return self::$configuration;
60 }
61
62 /**
63 * Save to database configuration instance
64 *
65 * @param MWP_Configuration_Conf $configuration
66 */
67 public function saveConfiguration(MWP_Configuration_Conf $configuration)
68 {
69 self::$configuration = $configuration;
70 $data = $configuration->toArray();
71 if (array_key_exists("master_cron_url", $data) && !empty($data['master_cron_url'])) {
72 /** @handled function fix */
73 update_option("mwp_worker_configuration", $data);
74 }
75 }
76 }
77