Newscoop\Service\Implementation\ThemeManagementServiceLocal::exportTheme PHP Метод

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

* ---------------------------------------------------------------
public exportTheme ( $theme, $p_errorMsg = '' )
    public function exportTheme($theme, $p_errorMsg = '')
    {
        $error_prefix = empty($p_errorMsg) ? '' : $p_errorMsg . "\n";
        Validation::notEmpty($theme, 'theme');
        if (!$theme instanceof Theme) {
            $theme = $this->findById($theme);
        }
        if (!file_exists($xpth = $this->toFullPath(self::FOLDER_EXPORTS))) {
            mkdir($xpth);
        }
        $zipFilePath = realpath($xpth);
        $zipFilePath = $zipFilePath . DIR_SEP . preg_replace('([^a-zA-Z0-9_\\-.]+)', '_', $theme->getName()) . '.zip';
        // create object
        $zip = new \ZipArchive();
        // open archive
        if ($zip->open($zipFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== TRUE) {
            die($error_prefix . 'Could not open archive');
        }
        $themePath = $this->toFullPath($theme->getPath());
        $themePathLength = strlen($themePath);
        // initialize an iterator
        // pass it the directory to be processed
        $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($themePath));
        // iterate over the directory
        // add each file found to the archive
        $addedDirs = array();
        foreach ($iterator as $key => $value) {
            $fname = substr($key, $themePathLength);
            if (strlen($fname) > 0 && !in_array(basename($fname), array('.', '..'))) {
                if (!in_array(dirname($fname), $addedDirs)) {
                    if (!$zip->addEmptyDir(dirname($fname))) {
                        return false;
                    }
                    $addedDirs[] = dirname($fname);
                }
                $zip->addFile(realpath($key), $fname) or die($error_prefix . "ERROR: Could not add file: {$key}");
            }
        }
        // close and save archive
        if (!$zip->close()) {
            return false;
        }
        return $zipFilePath;
    }