@@ -13,155 +13,155 @@ |
||
13 | 13 | * @package Intraxia\Jaxion |
14 | 14 | */ |
15 | 15 | class Application extends Container implements ApplicationContract { |
16 | - /** |
|
17 | - * Define plugin version on Application. |
|
18 | - */ |
|
19 | - const VERSION = ''; |
|
20 | - |
|
21 | - /** |
|
22 | - * Singleton instance of the Application object |
|
23 | - * |
|
24 | - * @var Application[] |
|
25 | - */ |
|
26 | - protected static $instances = array(); |
|
27 | - |
|
28 | - /** |
|
29 | - * Instantiates a new Application container. |
|
30 | - * |
|
31 | - * The Application constructor enforces the presence of of a single instance |
|
32 | - * of the Application. If an instance already exists, an Exception will be thrown. |
|
33 | - * |
|
34 | - * @param Config $config |
|
35 | - * @param array $providers |
|
36 | - * |
|
37 | - * @throws ApplicationAlreadyBootedException |
|
38 | - */ |
|
39 | - public function __construct( $config, array $providers = array() ) { |
|
40 | - if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
41 | - throw new ApplicationAlreadyBootedException; |
|
42 | - } |
|
43 | - |
|
44 | - static::$instances[ get_called_class() ] = $this; |
|
45 | - |
|
46 | - if ( ! ( $config instanceof Config ) ) { |
|
47 | - $config = new Config( ConfigType::PLUGIN, $config ); |
|
48 | - } |
|
49 | - |
|
50 | - $this->register_constants( $config ); |
|
51 | - $this->register_core_services( $config ); |
|
52 | - |
|
53 | - register_activation_hook( $config->file, array( $this, 'activate' ) ); |
|
54 | - register_deactivation_hook( $config->file, array( $this, 'deactivate' ) ); |
|
55 | - |
|
56 | - parent::__construct( $providers ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * |
|
62 | - * @throws UnexpectedValueException |
|
63 | - */ |
|
64 | - public function boot() { |
|
65 | - $loader = $this->fetch( 'loader' ); |
|
66 | - |
|
67 | - if ( ! ( $loader instanceof LoaderContract ) ) { |
|
68 | - throw new UnexpectedValueException; |
|
69 | - } |
|
70 | - |
|
71 | - foreach ( $this as $alias => $value ) { |
|
72 | - if ( $value instanceof HasActions ) { |
|
73 | - $loader->register_actions( $value ); |
|
74 | - } |
|
75 | - |
|
76 | - if ( $value instanceof HasFilters ) { |
|
77 | - $loader->register_filters( $value ); |
|
78 | - } |
|
79 | - |
|
80 | - if ( $value instanceof HasShortcode ) { |
|
81 | - $loader->register_shortcode( $value ); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - add_action( 'plugins_loaded', array( $loader, 'run' ) ); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * {@inheritdoc} |
|
90 | - * |
|
91 | - * @codeCoverageIgnore |
|
92 | - */ |
|
93 | - public function activate() { |
|
94 | - // no-op |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * {@inheritdoc} |
|
99 | - * |
|
100 | - * @codeCoverageIgnore |
|
101 | - */ |
|
102 | - public function deactivate() { |
|
103 | - // no-op |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * {@inheritDoc} |
|
108 | - * |
|
109 | - * @return Application |
|
110 | - * @throws ApplicationNotBootedException |
|
111 | - */ |
|
112 | - public static function instance() { |
|
113 | - if ( ! isset( static::$instances[ get_called_class() ] ) ) { |
|
114 | - throw new ApplicationNotBootedException; |
|
115 | - } |
|
116 | - |
|
117 | - return static::$instances[ get_called_class() ]; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * {@inheritDoc} |
|
122 | - */ |
|
123 | - public static function shutdown() { |
|
124 | - if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
125 | - unset( static::$instances[ get_called_class() ] ); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Sets the plugin's url, path, and basename. |
|
131 | - * |
|
132 | - * @param Config $config |
|
133 | - */ |
|
134 | - private function register_constants( Config $config ) { |
|
135 | - $this->share( 'file', function() use ( $config ) { |
|
136 | - return $config->file; |
|
137 | - } ); |
|
138 | - $this->share( 'url', function() use ( $config ) { |
|
139 | - return $config->url; |
|
140 | - } ); |
|
141 | - $this->share( 'path', function() use ( $config ) { |
|
142 | - return $config->path; |
|
143 | - } ); |
|
144 | - $this->share( 'basename', function() use ( $config ) { |
|
145 | - return $config->basename; |
|
146 | - } ); |
|
147 | - $this->share( 'slug', function() use ( $config ) { |
|
148 | - return $config->slug; |
|
149 | - } ); |
|
150 | - $this->share( 'version', static::VERSION ); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Registers the built-in services with the Application container. |
|
155 | - * |
|
156 | - * @param Config $config |
|
157 | - */ |
|
158 | - private function register_core_services( Config $config ) { |
|
159 | - $this->share( array( 'config' => 'Intraxia\Jaxion\Core\Config' ), $config ); |
|
160 | - $this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function () { |
|
161 | - return new Loader; |
|
162 | - } ); |
|
163 | - $this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( Container $app ) { |
|
164 | - return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) ); |
|
165 | - } ); |
|
166 | - } |
|
16 | + /** |
|
17 | + * Define plugin version on Application. |
|
18 | + */ |
|
19 | + const VERSION = ''; |
|
20 | + |
|
21 | + /** |
|
22 | + * Singleton instance of the Application object |
|
23 | + * |
|
24 | + * @var Application[] |
|
25 | + */ |
|
26 | + protected static $instances = array(); |
|
27 | + |
|
28 | + /** |
|
29 | + * Instantiates a new Application container. |
|
30 | + * |
|
31 | + * The Application constructor enforces the presence of of a single instance |
|
32 | + * of the Application. If an instance already exists, an Exception will be thrown. |
|
33 | + * |
|
34 | + * @param Config $config |
|
35 | + * @param array $providers |
|
36 | + * |
|
37 | + * @throws ApplicationAlreadyBootedException |
|
38 | + */ |
|
39 | + public function __construct( $config, array $providers = array() ) { |
|
40 | + if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
41 | + throw new ApplicationAlreadyBootedException; |
|
42 | + } |
|
43 | + |
|
44 | + static::$instances[ get_called_class() ] = $this; |
|
45 | + |
|
46 | + if ( ! ( $config instanceof Config ) ) { |
|
47 | + $config = new Config( ConfigType::PLUGIN, $config ); |
|
48 | + } |
|
49 | + |
|
50 | + $this->register_constants( $config ); |
|
51 | + $this->register_core_services( $config ); |
|
52 | + |
|
53 | + register_activation_hook( $config->file, array( $this, 'activate' ) ); |
|
54 | + register_deactivation_hook( $config->file, array( $this, 'deactivate' ) ); |
|
55 | + |
|
56 | + parent::__construct( $providers ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * |
|
62 | + * @throws UnexpectedValueException |
|
63 | + */ |
|
64 | + public function boot() { |
|
65 | + $loader = $this->fetch( 'loader' ); |
|
66 | + |
|
67 | + if ( ! ( $loader instanceof LoaderContract ) ) { |
|
68 | + throw new UnexpectedValueException; |
|
69 | + } |
|
70 | + |
|
71 | + foreach ( $this as $alias => $value ) { |
|
72 | + if ( $value instanceof HasActions ) { |
|
73 | + $loader->register_actions( $value ); |
|
74 | + } |
|
75 | + |
|
76 | + if ( $value instanceof HasFilters ) { |
|
77 | + $loader->register_filters( $value ); |
|
78 | + } |
|
79 | + |
|
80 | + if ( $value instanceof HasShortcode ) { |
|
81 | + $loader->register_shortcode( $value ); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + add_action( 'plugins_loaded', array( $loader, 'run' ) ); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * {@inheritdoc} |
|
90 | + * |
|
91 | + * @codeCoverageIgnore |
|
92 | + */ |
|
93 | + public function activate() { |
|
94 | + // no-op |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * {@inheritdoc} |
|
99 | + * |
|
100 | + * @codeCoverageIgnore |
|
101 | + */ |
|
102 | + public function deactivate() { |
|
103 | + // no-op |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * {@inheritDoc} |
|
108 | + * |
|
109 | + * @return Application |
|
110 | + * @throws ApplicationNotBootedException |
|
111 | + */ |
|
112 | + public static function instance() { |
|
113 | + if ( ! isset( static::$instances[ get_called_class() ] ) ) { |
|
114 | + throw new ApplicationNotBootedException; |
|
115 | + } |
|
116 | + |
|
117 | + return static::$instances[ get_called_class() ]; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * {@inheritDoc} |
|
122 | + */ |
|
123 | + public static function shutdown() { |
|
124 | + if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
125 | + unset( static::$instances[ get_called_class() ] ); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Sets the plugin's url, path, and basename. |
|
131 | + * |
|
132 | + * @param Config $config |
|
133 | + */ |
|
134 | + private function register_constants( Config $config ) { |
|
135 | + $this->share( 'file', function() use ( $config ) { |
|
136 | + return $config->file; |
|
137 | + } ); |
|
138 | + $this->share( 'url', function() use ( $config ) { |
|
139 | + return $config->url; |
|
140 | + } ); |
|
141 | + $this->share( 'path', function() use ( $config ) { |
|
142 | + return $config->path; |
|
143 | + } ); |
|
144 | + $this->share( 'basename', function() use ( $config ) { |
|
145 | + return $config->basename; |
|
146 | + } ); |
|
147 | + $this->share( 'slug', function() use ( $config ) { |
|
148 | + return $config->slug; |
|
149 | + } ); |
|
150 | + $this->share( 'version', static::VERSION ); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Registers the built-in services with the Application container. |
|
155 | + * |
|
156 | + * @param Config $config |
|
157 | + */ |
|
158 | + private function register_core_services( Config $config ) { |
|
159 | + $this->share( array( 'config' => 'Intraxia\Jaxion\Core\Config' ), $config ); |
|
160 | + $this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function () { |
|
161 | + return new Loader; |
|
162 | + } ); |
|
163 | + $this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( Container $app ) { |
|
164 | + return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) ); |
|
165 | + } ); |
|
166 | + } |
|
167 | 167 | } |
@@ -36,24 +36,24 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @throws ApplicationAlreadyBootedException |
38 | 38 | */ |
39 | - public function __construct( $config, array $providers = array() ) { |
|
40 | - if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
39 | + public function __construct($config, array $providers = array()) { |
|
40 | + if (isset(static::$instances[get_called_class()])) { |
|
41 | 41 | throw new ApplicationAlreadyBootedException; |
42 | 42 | } |
43 | 43 | |
44 | - static::$instances[ get_called_class() ] = $this; |
|
44 | + static::$instances[get_called_class()] = $this; |
|
45 | 45 | |
46 | - if ( ! ( $config instanceof Config ) ) { |
|
47 | - $config = new Config( ConfigType::PLUGIN, $config ); |
|
46 | + if (!($config instanceof Config)) { |
|
47 | + $config = new Config(ConfigType::PLUGIN, $config); |
|
48 | 48 | } |
49 | 49 | |
50 | - $this->register_constants( $config ); |
|
51 | - $this->register_core_services( $config ); |
|
50 | + $this->register_constants($config); |
|
51 | + $this->register_core_services($config); |
|
52 | 52 | |
53 | - register_activation_hook( $config->file, array( $this, 'activate' ) ); |
|
54 | - register_deactivation_hook( $config->file, array( $this, 'deactivate' ) ); |
|
53 | + register_activation_hook($config->file, array($this, 'activate')); |
|
54 | + register_deactivation_hook($config->file, array($this, 'deactivate')); |
|
55 | 55 | |
56 | - parent::__construct( $providers ); |
|
56 | + parent::__construct($providers); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,27 +62,27 @@ discard block |
||
62 | 62 | * @throws UnexpectedValueException |
63 | 63 | */ |
64 | 64 | public function boot() { |
65 | - $loader = $this->fetch( 'loader' ); |
|
65 | + $loader = $this->fetch('loader'); |
|
66 | 66 | |
67 | - if ( ! ( $loader instanceof LoaderContract ) ) { |
|
67 | + if (!($loader instanceof LoaderContract)) { |
|
68 | 68 | throw new UnexpectedValueException; |
69 | 69 | } |
70 | 70 | |
71 | - foreach ( $this as $alias => $value ) { |
|
72 | - if ( $value instanceof HasActions ) { |
|
73 | - $loader->register_actions( $value ); |
|
71 | + foreach ($this as $alias => $value) { |
|
72 | + if ($value instanceof HasActions) { |
|
73 | + $loader->register_actions($value); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( $value instanceof HasFilters ) { |
|
77 | - $loader->register_filters( $value ); |
|
76 | + if ($value instanceof HasFilters) { |
|
77 | + $loader->register_filters($value); |
|
78 | 78 | } |
79 | 79 | |
80 | - if ( $value instanceof HasShortcode ) { |
|
81 | - $loader->register_shortcode( $value ); |
|
80 | + if ($value instanceof HasShortcode) { |
|
81 | + $loader->register_shortcode($value); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - add_action( 'plugins_loaded', array( $loader, 'run' ) ); |
|
85 | + add_action('plugins_loaded', array($loader, 'run')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @throws ApplicationNotBootedException |
111 | 111 | */ |
112 | 112 | public static function instance() { |
113 | - if ( ! isset( static::$instances[ get_called_class() ] ) ) { |
|
113 | + if (!isset(static::$instances[get_called_class()])) { |
|
114 | 114 | throw new ApplicationNotBootedException; |
115 | 115 | } |
116 | 116 | |
117 | - return static::$instances[ get_called_class() ]; |
|
117 | + return static::$instances[get_called_class()]; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * {@inheritDoc} |
122 | 122 | */ |
123 | 123 | public static function shutdown() { |
124 | - if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
125 | - unset( static::$instances[ get_called_class() ] ); |
|
124 | + if (isset(static::$instances[get_called_class()])) { |
|
125 | + unset(static::$instances[get_called_class()]); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -131,23 +131,23 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param Config $config |
133 | 133 | */ |
134 | - private function register_constants( Config $config ) { |
|
135 | - $this->share( 'file', function() use ( $config ) { |
|
134 | + private function register_constants(Config $config) { |
|
135 | + $this->share('file', function() use ($config) { |
|
136 | 136 | return $config->file; |
137 | 137 | } ); |
138 | - $this->share( 'url', function() use ( $config ) { |
|
138 | + $this->share('url', function() use ($config) { |
|
139 | 139 | return $config->url; |
140 | 140 | } ); |
141 | - $this->share( 'path', function() use ( $config ) { |
|
141 | + $this->share('path', function() use ($config) { |
|
142 | 142 | return $config->path; |
143 | 143 | } ); |
144 | - $this->share( 'basename', function() use ( $config ) { |
|
144 | + $this->share('basename', function() use ($config) { |
|
145 | 145 | return $config->basename; |
146 | 146 | } ); |
147 | - $this->share( 'slug', function() use ( $config ) { |
|
147 | + $this->share('slug', function() use ($config) { |
|
148 | 148 | return $config->slug; |
149 | 149 | } ); |
150 | - $this->share( 'version', static::VERSION ); |
|
150 | + $this->share('version', static::VERSION); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @param Config $config |
157 | 157 | */ |
158 | - private function register_core_services( Config $config ) { |
|
159 | - $this->share( array( 'config' => 'Intraxia\Jaxion\Core\Config' ), $config ); |
|
160 | - $this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function () { |
|
158 | + private function register_core_services(Config $config) { |
|
159 | + $this->share(array('config' => 'Intraxia\Jaxion\Core\Config'), $config); |
|
160 | + $this->share(array('loader' => 'Intraxia\Jaxion\Contract\Core\Loader'), function() { |
|
161 | 161 | return new Loader; |
162 | 162 | } ); |
163 | - $this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( Container $app ) { |
|
164 | - return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) ); |
|
163 | + $this->share(array('i18n' => 'Intaxia\Jaxion\Contract\Core\I18n'), function(Container $app) { |
|
164 | + return new I18n($app->fetch('basename'), $app->fetch('path')); |
|
165 | 165 | } ); |
166 | 166 | } |
167 | 167 | } |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | * @param string $type |
58 | 58 | * @param string $file |
59 | 59 | */ |
60 | - public function __construct( $type, $file ) { |
|
61 | - $this->type = new ConfigType( $type ); |
|
60 | + public function __construct($type, $file) { |
|
61 | + $this->type = new ConfigType($type); |
|
62 | 62 | $this->file = $file; |
63 | 63 | |
64 | - switch ( $this->type->getValue() ) { |
|
64 | + switch ($this->type->getValue()) { |
|
65 | 65 | case ConfigType::PLUGIN: |
66 | 66 | case ConfigType::MU_PLUGIN: |
67 | - $this->url = plugin_dir_url( $file ); |
|
68 | - $this->path = plugin_dir_path( $file ); |
|
69 | - $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
67 | + $this->url = plugin_dir_url($file); |
|
68 | + $this->path = plugin_dir_path($file); |
|
69 | + $this->slug = dirname($this->basename = plugin_basename($file)); |
|
70 | 70 | break; |
71 | 71 | case ConfigType::THEME: |
72 | - $this->url = get_stylesheet_directory_uri() . '/'; |
|
73 | - $this->path = get_stylesheet_directory() . '/'; |
|
74 | - $this->slug = dirname( $this->basename = plugin_basename( $file ) ); |
|
72 | + $this->url = get_stylesheet_directory_uri().'/'; |
|
73 | + $this->path = get_stylesheet_directory().'/'; |
|
74 | + $this->slug = dirname($this->basename = plugin_basename($file)); |
|
75 | 75 | break; |
76 | 76 | } |
77 | 77 | } |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return array|null |
85 | 85 | */ |
86 | - public function get_config_json( $filename ) { |
|
87 | - if ( isset( $this->loaded[ $filename ] ) ) { |
|
88 | - return $this->loaded[ $filename ]; |
|
86 | + public function get_config_json($filename) { |
|
87 | + if (isset($this->loaded[$filename])) { |
|
88 | + return $this->loaded[$filename]; |
|
89 | 89 | } |
90 | 90 | |
91 | - $contents = file_get_contents( $this->path . 'config/' . $filename . '.json' ); |
|
91 | + $contents = file_get_contents($this->path.'config/'.$filename.'.json'); |
|
92 | 92 | |
93 | - if ( false === $contents ) { |
|
93 | + if (false === $contents) { |
|
94 | 94 | return null; |
95 | 95 | } |
96 | 96 | |
97 | - return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
97 | + return $this->loaded[$filename] = json_decode($contents, true); |
|
98 | 98 | } |
99 | 99 | } |
@@ -11,98 +11,98 @@ |
||
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 | - $contents = file_get_contents( $this->path . 'config/' . $filename . '.json' ); |
|
100 | + $contents = file_get_contents( $this->path . 'config/' . $filename . '.json' ); |
|
101 | 101 | |
102 | - if ( false === $contents ) { |
|
103 | - return null; |
|
104 | - } |
|
102 | + if ( false === $contents ) { |
|
103 | + return null; |
|
104 | + } |
|
105 | 105 | |
106 | - return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
107 | - } |
|
106 | + return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
107 | + } |
|
108 | 108 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | * @subpackage Core |
13 | 13 | */ |
14 | 14 | class ConfigType extends Enum { |
15 | - const PLUGIN = 'plugin'; |
|
16 | - const THEME = 'theme'; |
|
17 | - const MU_PLUGIN = 'mu-plugin'; |
|
15 | + const PLUGIN = 'plugin'; |
|
16 | + const THEME = 'theme'; |
|
17 | + const MU_PLUGIN = 'mu-plugin'; |
|
18 | 18 | } |