Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
atanas-dev committed Nov 2, 2019
1 parent a8bf6a7 commit 46e8dc5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 94 deletions.
3 changes: 0 additions & 3 deletions src/Assets/AssetsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Avatar/AvatarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 0 additions & 3 deletions src/Config/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Image/ImageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Sidebar/SidebarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
104 changes: 26 additions & 78 deletions src/Theme/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand All @@ -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' );
}

/**
Expand All @@ -145,7 +93,7 @@ public function partial( $partial, $child = '', $context = [] ) {

$templates[] = "views/partials/${partial}.php";

\WPEmerge\render( $templates, $context );
$this->app->render( $templates, $context );
}

/**
Expand All @@ -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();
}
}
31 changes: 31 additions & 0 deletions src/Theme/ThemeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace WPEmergeTheme\Theme;

use WPEmerge\ServiceProviders\ServiceProviderInterface;

/**
* Provide theme dependencies.
*
* @codeCoverageIgnore
*/
class ThemeServiceProvider implements ServiceProviderInterface {
/**
* {@inheritDoc}
*/
public function register( $container ) {
$container['wpemerge_theme.theme.theme'] = function( $c ) {
return new Theme( $c[ WPEMERGE_APPLICATION_KEY ] );
};

$app = $container[ WPEMERGE_APPLICATION_KEY ];
$app->alias( 'theme', 'wpemerge_theme.theme.theme' );
}

/**
* {@inheritDoc}
*/
public function bootstrap( $container ) {
// Nothing to bootstrap.
}
}

0 comments on commit 46e8dc5

Please sign in to comment.