@@ -4,7 +4,7 @@ |
||
| 4 | 4 | use MyCLabs\Enum\Enum; |
| 5 | 5 | |
| 6 | 6 | class ConfigType extends Enum { |
| 7 | - const PLUGIN = 'plugin'; |
|
| 8 | - const THEME = 'theme'; |
|
| 9 | - const MU_PLUGIN = 'mu-plugin'; |
|
| 7 | + const PLUGIN = 'plugin'; |
|
| 8 | + const THEME = 'theme'; |
|
| 9 | + const MU_PLUGIN = 'mu-plugin'; |
|
| 10 | 10 | } |
@@ -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 | } |
@@ -2,98 +2,98 @@ |
||
| 2 | 2 | namespace Intraxia\Jaxion\Core; |
| 3 | 3 | |
| 4 | 4 | class Config { |
| 5 | - /** |
|
| 6 | - * Configuration type. |
|
| 7 | - * |
|
| 8 | - * @var ConfigType |
|
| 9 | - */ |
|
| 10 | - public $type; |
|
| 5 | + /** |
|
| 6 | + * Configuration type. |
|
| 7 | + * |
|
| 8 | + * @var ConfigType |
|
| 9 | + */ |
|
| 10 | + public $type; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * App entry file. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $file; |
|
| 12 | + /** |
|
| 13 | + * App entry file. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $file; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * App url. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $url; |
|
| 19 | + /** |
|
| 20 | + * App url. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $url; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * App path. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - public $path; |
|
| 26 | + /** |
|
| 27 | + * App path. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + public $path; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * App slug. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $slug; |
|
| 33 | + /** |
|
| 34 | + * App slug. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $slug; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * App basename. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $basename; |
|
| 40 | + /** |
|
| 41 | + * App basename. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $basename; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Loaded configuration files. |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - private $loaded = array(); |
|
| 47 | + /** |
|
| 48 | + * Loaded configuration files. |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + private $loaded = array(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Config constructor. |
|
| 56 | - * |
|
| 57 | - * @param string $type |
|
| 58 | - * @param string $file |
|
| 59 | - */ |
|
| 60 | - public function __construct( $type, $file ) { |
|
| 61 | - $this->type = new ConfigType( $type ); |
|
| 62 | - $this->file = $file; |
|
| 54 | + /** |
|
| 55 | + * Config constructor. |
|
| 56 | + * |
|
| 57 | + * @param string $type |
|
| 58 | + * @param string $file |
|
| 59 | + */ |
|
| 60 | + public function __construct( $type, $file ) { |
|
| 61 | + $this->type = new ConfigType( $type ); |
|
| 62 | + $this->file = $file; |
|
| 63 | 63 | |
| 64 | - switch ( $this->type->getValue() ) { |
|
| 65 | - case ConfigType::PLUGIN: |
|
| 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 ) ); |
|
| 70 | - break; |
|
| 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 ) ); |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - } |
|
| 64 | + switch ( $this->type->getValue() ) { |
|
| 65 | + case ConfigType::PLUGIN: |
|
| 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 ) ); |
|
| 70 | + break; |
|
| 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 ) ); |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Load a configuration JSON file from the config folder. |
|
| 81 | - * |
|
| 82 | - * @param string $filename |
|
| 83 | - * |
|
| 84 | - * @return array|null |
|
| 85 | - */ |
|
| 86 | - public function get_config_json( $filename ) { |
|
| 87 | - if ( isset( $this->loaded[ $filename ] ) ) { |
|
| 88 | - return $this->loaded[ $filename ]; |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * Load a configuration JSON file from the config folder. |
|
| 81 | + * |
|
| 82 | + * @param string $filename |
|
| 83 | + * |
|
| 84 | + * @return array|null |
|
| 85 | + */ |
|
| 86 | + public function get_config_json( $filename ) { |
|
| 87 | + if ( isset( $this->loaded[ $filename ] ) ) { |
|
| 88 | + return $this->loaded[ $filename ]; |
|
| 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 ( $contents === false ) { |
|
| 94 | - return null; |
|
| 95 | - } |
|
| 93 | + if ( $contents === false ) { |
|
| 94 | + return null; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
| 98 | - } |
|
| 97 | + return $this->loaded[ $filename ] = json_decode( $contents, true ); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -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 ( $contents === false ) { |
|
| 93 | + if ($contents === false) { |
|
| 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 | } |