PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.1
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / Helper / Config.php

Config.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.1, at inc/Helper/Config.php

97 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LP\Helpers;
4
5 /**
6 * Class Config
7 * Read data config from file
8 *
9 * @package LP\Helpers
10 * @since 4.1.6.4
11 * @version 1.0.0
12 */
13 class Config {
14 /*
15 * All of configurations of items
16 *
17 * @var array
18 */
19 protected static $instance;
20 protected $file_name = '';
21 protected $items = array();
22 /**
23 * @var array Array name files config.
24 */
25 protected $config_files = array();
26 /**
27 * @var string Folder store files config
28 */
29 protected $dir;
30
31 /**
32 * Config constructor.
33 *
34 * @param array $items
35 */
36 protected function __construct( array $items = array() ) {
37 $this->dir = LP_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
38
39 $this->items = $items;
40 }
41
42 /**
43 * Get the specified configuration value
44 *
45 * @param string $key | Format key: file_name:key_name:key_item:...
46 * @param string $path | from folder 'config'
47 *
48 * @return array|mixed
49 * @version 1.0.0
50 * @since 4.1.6.4
51 */
52 public function get( string $key = '', string $path = '' ) {
53 $data_config = array();
54 $data_config_by_key = array();
55
56 if ( empty( $key ) ) {
57 return $data_config;
58 }
59
60 $keys = explode( ':', $key );
61 $file_name = $keys[0];
62 $file_path = $this->dir . $path . DIRECTORY_SEPARATOR . $file_name . '.php';
63
64 if ( ! file_exists( $file_path ) ) {
65 return $data_config;
66 }
67
68 $store_file_config = $this->config_files[ $file_name ] ?? array();
69 if ( empty( $store_file_config ) ) {
70 $this->config_files[ $file_name ] = include $file_path;
71 }
72
73 $data_config = $this->config_files[ $file_name ];
74
75 $number_keys = count( $keys );
76
77 if ( 1 === $number_keys ) {
78 return $data_config;
79 } else {
80 $data_config_by_key = $data_config;
81 for ( $i = 1; $i < $number_keys; $i ++ ) {
82 $data_config_by_key = $data_config_by_key[ $keys[ $i ] ] ?? array();
83 }
84
85 return $data_config_by_key;
86 }
87 }
88
89 public static function instance(): self {
90 if ( is_null( self::$instance ) ) {
91 self::$instance = new self();
92 }
93
94 return self::$instance;
95 }
96 }
97