@@ -11,104 +11,104 @@ |
||
| 11 | 11 | * @subpackage Core |
| 12 | 12 | */ |
| 13 | 13 | class Config { |
| 14 | - /** |
|
| 15 | - * Configuration type. |
|
| 16 | - * |
|
| 17 | - * @var ConfigType |
|
| 18 | - */ |
|
| 19 | - public $type; |
|
| 14 | + /** |
|
| 15 | + * Configuration type. |
|
| 16 | + * |
|
| 17 | + * @var ConfigType |
|
| 18 | + */ |
|
| 19 | + public $type; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * App entry file. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - public $file; |
|
| 21 | + /** |
|
| 22 | + * App entry file. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + public $file; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * App url. |
|
| 30 | - * |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - public $url; |
|
| 28 | + /** |
|
| 29 | + * App url. |
|
| 30 | + * |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + public $url; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * App path. |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - public $path; |
|
| 35 | + /** |
|
| 36 | + * App path. |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + public $path; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * App slug. |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - public $slug; |
|
| 42 | + /** |
|
| 43 | + * App slug. |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + public $slug; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * App basename. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - public $basename; |
|
| 49 | + /** |
|
| 50 | + * App basename. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + public $basename; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Loaded configuration files. |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - private $loaded = array(); |
|
| 56 | + /** |
|
| 57 | + * Loaded configuration files. |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + private $loaded = array(); |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Config constructor. |
|
| 65 | - * |
|
| 66 | - * @param string $type |
|
| 67 | - * @param string $file |
|
| 68 | - */ |
|
| 69 | - public function __construct( $type, $file ) { |
|
| 70 | - $this->type = new ConfigType( $type ); |
|
| 71 | - $this->file = $file; |
|
| 63 | + /** |
|
| 64 | + * Config constructor. |
|
| 65 | + * |
|
| 66 | + * @param string $type |
|
| 67 | + * @param string $file |
|
| 68 | + */ |
|
| 69 | + public function __construct( $type, $file ) { |
|
| 70 | + $this->type = new ConfigType( $type ); |
|
| 71 | + $this->file = $file; |
|
| 72 | 72 | |
| 73 | - switch ( $this->type->getValue() ) { |
|
| 74 | - case ConfigType::PLUGIN: |
|
| 75 | - case ConfigType::MU_PLUGIN: |
|
| 76 | - $this->url = plugin_dir_url( $file ); |
|
| 77 | - $this->path = plugin_dir_path( $file ); |
|
| 78 | - $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
| 79 | - break; |
|
| 80 | - case ConfigType::THEME: |
|
| 81 | - $this->url = get_stylesheet_directory_uri() . '/'; |
|
| 82 | - $this->path = get_stylesheet_directory() . '/'; |
|
| 83 | - $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
| 84 | - break; |
|
| 85 | - } |
|
| 86 | - } |
|
| 73 | + switch ( $this->type->getValue() ) { |
|
| 74 | + case ConfigType::PLUGIN: |
|
| 75 | + case ConfigType::MU_PLUGIN: |
|
| 76 | + $this->url = plugin_dir_url( $file ); |
|
| 77 | + $this->path = plugin_dir_path( $file ); |
|
| 78 | + $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
| 79 | + break; |
|
| 80 | + case ConfigType::THEME: |
|
| 81 | + $this->url = get_stylesheet_directory_uri() . '/'; |
|
| 82 | + $this->path = get_stylesheet_directory() . '/'; |
|
| 83 | + $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
| 84 | + break; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Load a configuration JSON file from the config folder. |
|
| 90 | - * |
|
| 91 | - * @param string $filename |
|
| 92 | - * |
|
| 93 | - * @return array|null |
|
| 94 | - */ |
|
| 95 | - public function get_config_json( $filename ) { |
|
| 96 | - if ( isset( $this->loaded[ $filename ] ) ) { |
|
| 97 | - return $this->loaded[ $filename ]; |
|
| 98 | - } |
|
| 88 | + /** |
|
| 89 | + * Load a configuration JSON file from the config folder. |
|
| 90 | + * |
|
| 91 | + * @param string $filename |
|
| 92 | + * |
|
| 93 | + * @return array|null |
|
| 94 | + */ |
|
| 95 | + public function get_config_json( $filename ) { |
|
| 96 | + if ( isset( $this->loaded[ $filename ] ) ) { |
|
| 97 | + return $this->loaded[ $filename ]; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - $config = $this->path . 'config/' . $filename . '.json'; |
|
| 100 | + $config = $this->path . 'config/' . $filename . '.json'; |
|
| 101 | 101 | |
| 102 | - if ( ! file_exists( $config ) ) { |
|
| 103 | - return null; |
|
| 104 | - } |
|
| 102 | + if ( ! file_exists( $config ) ) { |
|
| 103 | + return null; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - $contents = file_get_contents( $config ); |
|
| 106 | + $contents = file_get_contents( $config ); |
|
| 107 | 107 | |
| 108 | - if ( false === $contents ) { |
|
| 109 | - return null; |
|
| 110 | - } |
|
| 108 | + if ( false === $contents ) { |
|
| 109 | + return null; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
| 113 | - } |
|
| 112 | + return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
| 113 | + } |
|
| 114 | 114 | } |