Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
webbingbrasil/themes-module / Providers / ThemesServiceProvider.php
Size: Mime:
<?php
namespace Modules\Themes\Providers;

use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\AggregateServiceProvider;
use Modules\Themes\Html\ThemeHtmlBuilder;
use Modules\Themes\Theme\Loader;

class ThemesServiceProvider extends AggregateServiceProvider
{
    /**
     * Themes provides the HtmlServiceProvider for ease-of-use.
     *
     * @var array
     */
    protected $providers = [
        'Collective\Html\HtmlServiceProvider'
    ];

    /**
     * Registers the various bindings required by other packages.
     */
    public function register()
    {

        parent::register();
        $this->registerTranslations();
        $this->registerConfig();
        $this->registerViews();
        $this->registerThemes();
        $this->registerAliases();
        $this->registerThemeBuilder();
        $this->registerCommands();
    }

    /**
     * Register translations.
     *
     * @return void
     */
    public function registerTranslations()
    {
        $langPath = base_path('resources/lang/modules/themes');

        if (is_dir($langPath)) {
            $this->loadTranslationsFrom($langPath, 'themes');
        } else {
            $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'themes');
        }
    }

    /**
     * Register config.
     *
     * @return void
     */
    protected function registerConfig()
    {
        $this->publishes([
            __DIR__ . '/../Config/config.php' => config_path('themes.php'),
        ]);
        $this->mergeConfigFrom(
            __DIR__ . '/../Config/config.php', 'themes'
        );
        /**
         *
         */
        $this->publishes([
            __DIR__ . '/../Config/config.php' => config_path('themes.php'),
        ]);
        $this->mergeConfigFrom(
            __DIR__ . '/../Config/config.php', 'themes'
        );
    }

    /**
     * Register views.
     *
     * @return void
     */
    public function registerViews()
    {
        $viewPath = base_path('resources/views/modules/themes');

        $sourcePath = __DIR__ . '/../Resources/views';

        $this->publishes([
            $sourcePath => $viewPath
        ]);

        $this->loadViewsFrom([$viewPath, $sourcePath], 'themes');
    }

    /**
     * Sets up the object that will be used for theme registration calls.
     */
    protected function registerThemes()
    {
        $this->app->singleton('themes', function ($app) {
            return new \Modules\Themes\Theme\Themes(new Loader, $app);
        });
    }

    /**
     * Themes class should be accessible from global scope for ease of use.
     */
    private function registerAliases()
    {
        $this->app->alias('themes', 'Modules\Themes\Theme\Themes');
        $aliasLoader = AliasLoader::getInstance();

        $aliasLoader->alias('Themes', \Modules\Themes\Facades\ThemesFacade::class);
        $aliasLoader->alias('Theme', \Modules\Themes\Facades\ThemeFacade::class);

    }

    /**
     * Create the binding necessary for the theme html builder.
     */
    protected function registerThemeBuilder()
    {
        $this->app->singleton('themes.theme', function ($app) {
            return new ThemeHtmlBuilder($app['html'], $app['url']);
        });
    }

    /**
     * Register the commands available to the package.
     */
    private function registerCommands()
    {
        $this->commands(
            'Modules\Themes\Console\PublishAssetsCommand',
            'Modules\Themes\Console\ListCommand'
        );
    }

    /**
     * Boot the package, in this case also discovering any themes required by Themes.
     */
    public function boot()
    {
        $this->bootThemes();
    }

    /**
     * Once the provided has booted, we can now look at configuration and see if there's
     * any paths defined to automatically load and register the required themes.
     */
    protected function bootThemes()
    {
        $paths = \Config::get('themes.paths', []);
        foreach ($paths as $path) {
            $themePaths = \Themes::discover($path);
            \Themes::registerPaths($themePaths);
        }

        $theme = $this->app['config']->get('themes.activate', null);

        if (!is_null($theme)) {
            \Themes::activate($theme);
        }
    }

    /**
     * An array of classes that Themes provides.
     *
     * @return array
     */
    public function provides()
    {
        return array_merge(parent::provides(), [
            'Themes',
            'Theme'
        ]);
    }

}