Prado\Web\UI\TTheme::__construct PHP Метод

__construct() публичный Метод

Constructor.
public __construct ( $themePath, $themeUrl )
    public function __construct($themePath, $themeUrl)
    {
        $this->_themeUrl = $themeUrl;
        $this->_themePath = realpath($themePath);
        $this->_name = basename($themePath);
        $cacheValid = false;
        // TODO: the following needs to be cleaned up (Qiang)
        if (($cache = $this->getApplication()->getCache()) !== null) {
            $array = $cache->get(self::THEME_CACHE_PREFIX . $themePath);
            if (is_array($array)) {
                list($skins, $cssFiles, $jsFiles, $timestamp) = $array;
                if ($this->getApplication()->getMode() !== TApplicationMode::Performance) {
                    if (($dir = opendir($themePath)) === false) {
                        throw new TIOException('theme_path_inexistent', $themePath);
                    }
                    $cacheValid = true;
                    while (($file = readdir($dir)) !== false) {
                        if ($file === '.' || $file === '..') {
                            continue;
                        } else {
                            if (basename($file, '.css') !== $file) {
                                $this->_cssFiles[] = $themeUrl . '/' . $file;
                            } else {
                                if (basename($file, '.js') !== $file) {
                                    $this->_jsFiles[] = $themeUrl . '/' . $file;
                                } else {
                                    if (basename($file, self::SKIN_FILE_EXT) !== $file && filemtime($themePath . DIRECTORY_SEPARATOR . $file) > $timestamp) {
                                        $cacheValid = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    closedir($dir);
                    if ($cacheValid) {
                        $this->_skins = $skins;
                    }
                } else {
                    $cacheValid = true;
                    $this->_cssFiles = $cssFiles;
                    $this->_jsFiles = $jsFiles;
                    $this->_skins = $skins;
                }
            }
        }
        if (!$cacheValid) {
            $this->_cssFiles = array();
            $this->_jsFiles = array();
            $this->_skins = array();
            if (($dir = opendir($themePath)) === false) {
                throw new TIOException('theme_path_inexistent', $themePath);
            }
            while (($file = readdir($dir)) !== false) {
                if ($file === '.' || $file === '..') {
                    continue;
                } else {
                    if (basename($file, '.css') !== $file) {
                        $this->_cssFiles[] = $themeUrl . '/' . $file;
                    } else {
                        if (basename($file, '.js') !== $file) {
                            $this->_jsFiles[] = $themeUrl . '/' . $file;
                        } else {
                            if (basename($file, self::SKIN_FILE_EXT) !== $file) {
                                $template = new TTemplate(file_get_contents($themePath . '/' . $file), $themePath, $themePath . '/' . $file);
                                foreach ($template->getItems() as $skin) {
                                    if (!isset($skin[2])) {
                                        // a text string, ignored
                                        continue;
                                    } else {
                                        if ($skin[0] !== -1) {
                                            throw new TConfigurationException('theme_control_nested', $skin[1], dirname($themePath));
                                        }
                                    }
                                    $type = $skin[1];
                                    $id = isset($skin[2]['skinid']) ? $skin[2]['skinid'] : 0;
                                    unset($skin[2]['skinid']);
                                    if (isset($this->_skins[$type][$id])) {
                                        throw new TConfigurationException('theme_skinid_duplicated', $type, $id, dirname($themePath));
                                    }
                                    /*
                                    foreach($skin[2] as $name=>$value)
                                    {
                                    	if(is_array($value) && ($value[0]===TTemplate::CONFIG_DATABIND || $value[0]===TTemplate::CONFIG_PARAMETER))
                                    		throw new TConfigurationException('theme_databind_forbidden',dirname($themePath),$type,$id);
                                    }
                                    */
                                    $this->_skins[$type][$id] = $skin[2];
                                }
                            }
                        }
                    }
                }
            }
            closedir($dir);
            sort($this->_cssFiles);
            sort($this->_jsFiles);
            if ($cache !== null) {
                $cache->set(self::THEME_CACHE_PREFIX . $themePath, array($this->_skins, $this->_cssFiles, $this->_jsFiles, time()));
            }
        }
    }