/** * Factory of X_Egg: accepts a manifest file or a xegg (zip) archive * @param string $eggfile path to manifest file or xegg file * @param string $dest_basepath destination root path * @param string $tmp_path temp dir for xegg unpack (ignored if $eggfile is a manifest) * @param bool $disableExtCheck allow to disable zip xegg file type check * @return X_Egg */ public static function factory($eggfile, $dest_basepath, $tmp_path = false, $disableExtCheck = false) { $egg = new X_Egg(); // i have to unzip egg file if it is not a xml $extension = strtolower(pathinfo($eggfile, PATHINFO_EXTENSION)); if ($extension == 'xml') { // i only have to read it $manifestFile = $eggfile; $basepath = dirname($eggfile); } elseif ($disableExtCheck || $extension == 'zip' || $extension == 'xegg') { // i have to unpack the zip file $pclzip = new PclZip($eggfile); if ($tmp_path === false) { $tmp_path = sys_get_temp_dir() . '/x_egg_unzip/'; } else { $tmp_path = rtrim($tmp_path, '\\/') . '/'; } $egg->_cleanFlag = true; $pclzip->extract(PCLZIP_OPT_PATH, $tmp_path); $manifestFile = $tmp_path . 'manifest.xml'; $basepath = $tmp_path; } else { throw new Exception("Invalid X_Egg file extensions. Valid extension are 'xegg' or 'zip'"); } $egg->setDestinationPath($dest_basepath)->setBasePath($basepath)->parse($manifestFile); return $egg; }