1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 
<?php
namespace Omeka\Site\Theme;

class Manager
{
    const STATE_ACTIVE = 'active';
    const STATE_INVALID_INI = 'invalid_ini';
    const STATE_INVALID_OMEKA_VERSION = 'invalid_omeka_version';
    const STATE_NOT_FOUND = 'not_found';

    /**
     * @var array Registered themes
     */
    protected $themes = [];

    /**
     * @var Theme|null The current theme
     */
    protected $currentTheme;

    /**
     * Register a new theme.
     *
     * @param string $id
     * @return Theme
     */
    public function registerTheme($id)
    {
        $theme = new Theme($id);
        $this->themes[$id] = $theme;
        return $theme;
    }

    /**
     * Check whether the theme INI is valid.
     *
     * @param Theme $theme
     * @return bool
     */
    public function iniIsValid(Theme $theme)
    {
        $ini = $theme->getIni();
        if (!isset($ini['name'])) {
            return false;
        }
        return true;
    }

    /**
     * Check whether a theme is registered.
     *
     * @param string $id
     * @return bool
     */
    public function isRegistered($id)
    {
        return array_key_exists($id, $this->themes);
    }

    /**
     * Get a registered theme.
     *
     * @param string $id
     * @return Theme|false Returns false when id is invalid
     */
    public function getTheme($id)
    {
        return $this->isRegistered($id) ? $this->themes[$id] : false;
    }

    /**
     * Get all registered themes.
     *
     * @return array
     */
    public function getThemes()
    {
        return $this->themes;
    }

    /**
     * Set the current theme.
     *
     * @param Theme $theme
     */
    public function setCurrentTheme(Theme $theme)
    {
        $this->currentTheme = $theme;
    }

    /**
     * Get the current theme.
     *
     * @return Theme|null
     */
    public function getCurrentTheme()
    {
        return $this->currentTheme;
    }
}