@@ -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 | } |
@@ -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 | } |
@@ -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 | } |