igaster\laravelTheme\Themes::set PHP Method

set() public method

Set $themeName is the active Theme
public set ( string $themeName ) : void
$themeName string
return void
    public function set($themeName)
    {
        if (!Config::get('themes.enabled', true)) {
            return;
        }
        if (!($theme = $this->find($themeName))) {
            $theme = $this->add(new Theme($themeName));
        }
        $this->activeTheme = $theme;
        // Build Paths array.
        // All paths are relative to Config::get('theme.theme_path')
        $paths = [];
        do {
            if (substr($theme->viewsPath, 0, 1) === DIRECTORY_SEPARATOR) {
                $path = base_path(substr($theme->viewsPath, 1));
            } else {
                $path = $this->themesPath;
                $path .= empty($theme->viewsPath) ? '' : DIRECTORY_SEPARATOR . $theme->viewsPath;
            }
            if (!in_array($path, $paths)) {
                $paths[] = $path;
            }
        } while ($theme = $theme->getParent());
        // fall-back to default paths (set in views.php config file)
        foreach ($this->defaultViewsPath as $path) {
            if (!in_array($path, $paths)) {
                $paths[] = $path;
            }
        }
        Config::set('view.paths', $paths);
        $themeViewFinder = app('view.finder');
        $themeViewFinder->setPaths($paths);
        \Event::fire('igaster.laravel-theme.change', $this->activeTheme);
    }

Usage Example

Beispiel #1
1
 public function testSetTheme()
 {
     $themes = new Themes();
     $theme1 = new Theme('theme1');
     $theme2 = new Theme('theme2');
     $themes->add($theme1);
     $themes->add($theme2);
     $themes->set('theme1');
     $this->assertEquals('theme1', $themes->get());
 }