From 46e8dc5c931ca749a89121f4ff88f906d61f44e0 Mon Sep 17 00:00:00 2001 From: Atanas Angelov Date: Sun, 3 Nov 2019 01:32:29 +0200 Subject: [PATCH] WIP --- src/Assets/AssetsServiceProvider.php | 3 - src/Avatar/AvatarServiceProvider.php | 5 +- src/Config/ConfigServiceProvider.php | 3 - src/Image/ImageServiceProvider.php | 3 - src/Sidebar/SidebarServiceProvider.php | 3 - src/Theme/Theme.php | 104 +++++++------------------ src/Theme/ThemeServiceProvider.php | 31 ++++++++ 7 files changed, 58 insertions(+), 94 deletions(-) create mode 100644 src/Theme/ThemeServiceProvider.php diff --git a/src/Assets/AssetsServiceProvider.php b/src/Assets/AssetsServiceProvider.php index 1ab9ba0..2ab275e 100644 --- a/src/Assets/AssetsServiceProvider.php +++ b/src/Assets/AssetsServiceProvider.php @@ -21,9 +21,6 @@ public function register( $container ) { $container['wpemerge_theme.assets.assets'] = function( $container ) { return new Assets( $container['wpemerge_theme.assets.manifest'] ); }; - - $app = $container[ WPEMERGE_APPLICATION_KEY ]; - $app->alias( 'Theme\\Assets', \WPEmergeTheme\Facades\Assets::class ); } /** diff --git a/src/Avatar/AvatarServiceProvider.php b/src/Avatar/AvatarServiceProvider.php index bc325b3..cc37a05 100644 --- a/src/Avatar/AvatarServiceProvider.php +++ b/src/Avatar/AvatarServiceProvider.php @@ -17,15 +17,12 @@ public function register( $container ) { $container['wpemerge_theme.avatar.avatar'] = function() { return new Avatar(); }; - - $app = $container[ WPEMERGE_APPLICATION_KEY ]; - $app->alias( 'Theme\\Avatar', \WPEmergeTheme\Facades\Avatar::class ); } /** * {@inheritDoc} */ public function bootstrap( $container ) { - \WPEmergeTheme\Facades\Avatar::bootstrap(); + $container['wpemerge_theme.avatar.avatar']->bootstrap(); } } diff --git a/src/Config/ConfigServiceProvider.php b/src/Config/ConfigServiceProvider.php index 6d82a3a..d4a7e61 100644 --- a/src/Config/ConfigServiceProvider.php +++ b/src/Config/ConfigServiceProvider.php @@ -17,9 +17,6 @@ public function register( $container ) { $container['wpemerge_theme.config.config'] = function() { return new Config(); }; - - $app = $container[ WPEMERGE_APPLICATION_KEY ]; - $app->alias( 'Theme\\Config', \WPEmergeTheme\Facades\Config::class ); } /** diff --git a/src/Image/ImageServiceProvider.php b/src/Image/ImageServiceProvider.php index 94b4aa6..c893842 100644 --- a/src/Image/ImageServiceProvider.php +++ b/src/Image/ImageServiceProvider.php @@ -17,9 +17,6 @@ public function register( $container ) { $container['wpemerge_theme.image.image'] = function() { return new Image(); }; - - $app = $container[ WPEMERGE_APPLICATION_KEY ]; - $app->alias( 'Theme\\Image', \WPEmergeTheme\Facades\Image::class ); } /** diff --git a/src/Sidebar/SidebarServiceProvider.php b/src/Sidebar/SidebarServiceProvider.php index 439677b..1efc87b 100644 --- a/src/Sidebar/SidebarServiceProvider.php +++ b/src/Sidebar/SidebarServiceProvider.php @@ -17,9 +17,6 @@ public function register( $container ) { $container['wpemerge_theme.sidebar.sidebar'] = function() { return new Sidebar(); }; - - $app = $container[ WPEMERGE_APPLICATION_KEY ]; - $app->alias( 'Theme\\Sidebar', \WPEmergeTheme\Facades\Sidebar::class ); } /** diff --git a/src/Theme/Theme.php b/src/Theme/Theme.php index 2fadb0b..2fb78c2 100644 --- a/src/Theme/Theme.php +++ b/src/Theme/Theme.php @@ -3,14 +3,6 @@ namespace WPEmergeTheme\Theme; use WPEmerge\Application\Application; -use WPEmerge\Exceptions\ConfigurationException; -use WPEmergeTheme\Assets\AssetsServiceProvider; -use WPEmergeTheme\Avatar\AvatarServiceProvider; -use WPEmergeTheme\Config\ConfigServiceProvider; -use WPEmergeTheme\Facades\Assets; -use WPEmergeTheme\Facades\Theme as ThemeFacade; -use WPEmergeTheme\Image\ImageServiceProvider; -use WPEmergeTheme\Sidebar\SidebarServiceProvider; /** * Main communication channel with the theme. @@ -23,43 +15,6 @@ class Theme { */ protected $app = null; - /** - * Flag whether the theme has been bootstrapped. - * - * @var boolean - */ - protected $bootstrapped = false; - - /** - * Array of theme service providers. - * - * @var string[] - */ - protected $service_providers = [ - AssetsServiceProvider::class, - AvatarServiceProvider::class, - ConfigServiceProvider::class, - ImageServiceProvider::class, - SidebarServiceProvider::class, - ]; - - /** - * Make a new theme instance. - * - * @return self - */ - public static function make() { - $app = Application::make(); - $theme = new self( $app ); - - $container = $app->getContainer(); - $container['wpemerge_theme'] = $theme; - - $app->alias( 'WPEmergeTheme', ThemeFacade::class ); - - return $theme; - } - /** * Constructor. * @@ -70,55 +25,48 @@ public function __construct( $app ) { } /** - * Get application instance. + * Shortcut to \WPEmergeTheme\Assets\Assets. * - * @return Application + * @return \WPEmergeTheme\Assets\Assets */ - public function getApplication() { - return $this->app; + public function assets() { + return $this->app->resolve( 'wpemerge_theme.assets.assets' ); } /** - * Get whether the theme has been bootstrapped. + * Shortcut to \WPEmergeTheme\Avatar\Avatar. * - * @return boolean + * @return \WPEmergeTheme\Avatar\Avatar */ - public function isBootstrapped() { - return $this->bootstrapped; + public function avatar() { + return $this->app->resolve( 'wpemerge_theme.avatar.avatar' ); } /** - * Bootstrap WPEmerge. + * Shortcut to \WPEmergeTheme\Config\Config. * - * @param array $config - * @return void + * @return \WPEmergeTheme\Config\Config */ - protected function bootstrapApplication( $config ) { - if ( ! isset( $config['providers'] ) ) { - $config['providers'] = []; - } - - $config['providers'] = array_merge( - $config['providers'], - $this->service_providers - ); - - $this->getApplication()->bootstrap( $config ); + public function config() { + return $this->app->resolve( 'wpemerge_theme.config.config' ); } /** - * Bootstrap the theme. + * Shortcut to \WPEmergeTheme\Image\Image. * - * @param array $config - * @return void + * @return \WPEmergeTheme\Image\Image */ - public function bootstrap( $config = [] ) { - if ( $this->isBootstrapped() ) { - throw new ConfigurationException( static::class . ' already bootstrapped.' ); - } + public function image() { + return $this->app->resolve( 'wpemerge_theme.image.image' ); + } - $this->bootstrapped = true; - $this->bootstrapApplication( $config ); + /** + * Shortcut to \WPEmergeTheme\Sidebar\Sidebar. + * + * @return \WPEmergeTheme\Sidebar\Sidebar + */ + public function sidebar() { + return $this->app->resolve( 'wpemerge_theme.sidebar.sidebar' ); } /** @@ -145,7 +93,7 @@ public function partial( $partial, $child = '', $context = [] ) { $templates[] = "views/partials/${partial}.php"; - \WPEmerge\render( $templates, $context ); + $this->app->render( $templates, $context ); } /** @@ -155,6 +103,6 @@ public function partial( $partial, $child = '', $context = [] ) { * @return string */ public function uri() { - return Assets::getThemeUri(); + return $this->app->resolve( 'wpemerge_theme.assets.assets' )->getThemeUri(); } } diff --git a/src/Theme/ThemeServiceProvider.php b/src/Theme/ThemeServiceProvider.php new file mode 100644 index 0000000..31ab1f1 --- /dev/null +++ b/src/Theme/ThemeServiceProvider.php @@ -0,0 +1,31 @@ +alias( 'theme', 'wpemerge_theme.theme.theme' ); + } + + /** + * {@inheritDoc} + */ + public function bootstrap( $container ) { + // Nothing to bootstrap. + } +}