本文整理汇总了PHP中PharData::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP PharData::getMetadata方法的具体用法?PHP PharData::getMetadata怎么用?PHP PharData::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PharData
的用法示例。
在下文中一共展示了PharData::getMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$dialog = $this->getHelperSet()->get('dialog');
$_configuration = $this->getHelper('configuration')->getConfiguration();
$file = $input->getArgument('file');
$connection = $this->getHelper('configuration')->getConnection();
if (is_file($file) && is_readable($file)) {
$phar = new \PharData($file);
if ($phar->hasMetadata()) {
$langInfo = $phar->getMetadata();
$connection = $this->getHelper('configuration')->getConnection();
if ($connection) {
$q = mysql_query("SELECT * FROM language WHERE dokeos_folder = '{$langInfo['dokeos_folder']}' ");
$langInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC);
$langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfoFromDB['dokeos_folder'];
if ($langInfoFromDB && $langFolderPath) {
//Overwrite lang files
if (!$dialog->askConfirmation($output, '<question>The ' . $langInfo['original_name'] . ' language already exists in Chamilo. Did you want to overwrite the contents? (y/N)</question>', false)) {
return;
}
if (is_writable($langFolderPath)) {
$output->writeln("Trying to save files here: {$langFolderPath}");
$phar->extractTo($langFolderPath, null, true);
// extract all files
$output->writeln("Files were copied.");
} else {
$output->writeln("<error>Make sure that this folder {$langFolderPath} has writable permissions or execute the script with sudo </error>");
}
} else {
//Check if parent_id exists
$parentId = '';
if (!empty($langInfo['parent_id'])) {
$sql = "select selected_value from settings_current where variable = 'allow_use_sub_language'";
$result = mysql_query($sql);
$subLanguageSetting = mysql_fetch_array($result, MYSQL_ASSOC);
$subLanguageSetting = $subLanguageSetting['selected_value'];
if ($subLanguageSetting == 'true') {
$q = mysql_query("SELECT * FROM language WHERE id = '{$langInfo['parent_id']}' ");
$parentLangInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC);
if ($parentLangInfoFromDB) {
$output->writeln("Setting parent language: " . $parentLangInfoFromDB['original_name']);
$parentId = $langInfo['parent_id'];
} else {
$output->writeln("The lang parent_id = {$langInfo['parent_id']} does not exist in Chamilo. Try to import first the parent language.");
exit;
}
} else {
$output->writeln("<comment>Please turn ON the sublanguage feature in this portal</comment>");
exit;
}
} else {
$output->writeln("Parent language was not provided");
}
$q = mysql_query("INSERT INTO language (original_name, english_name, isocode, dokeos_folder, available, parent_id) VALUES (\n '" . $langInfo['original_name'] . "',\n '" . $langInfo['english_name'] . "',\n '" . $langInfo['isocode'] . "',\n '" . $langInfo['dokeos_folder'] . "',\n '1',\n '" . $parentId . "')");
if ($q) {
$output->writeln("Language inserted in the DB");
$langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfo['dokeos_folder'];
$phar->extractTo($langFolderPath, null, true);
// extract all files
$output->writeln("<comment>Files were copied here {$langFolderPath} </comment>");
} else {
$output->writeln("An error ocurred while tring to create the language");
}
}
}
} else {
$output->writeln("<comment>The file is not a valid Chamilo language package<comment>");
}
} else {
$output->writeln("<comment>The file located in '{$file}' is not accessible<comment>");
}
}
示例2: toZip
function toZip()
{
if (isset($this->zip)) {
return;
}
if (file_exists($this->file . '.zip')) {
try {
$p = new \PharData($this->file . '.zip');
} catch (\Exception $e) {
}
if ($p->getMetadata() && is_string($p->getMetadata()) && isset($p[$p->getMetadata()])) {
if (isset($this->tar)) {
$test = $this->tar;
} elseif (isset($this->tgz)) {
$test = $this->tgz;
} else {
$test = $this->phar;
}
if ($p->getMetadata() === $test->getMetadata()) {
try {
// do both store the same package.xml and are they
// identical package.xml?
if ($p[$p->getMetadata()]->getContent() == $test[$p->getMetadata()]->getContent()) {
$this->zip = $p;
// yes
if ($this->outfile) {
copy($this->file . '.zip', $this->outfile . '.zip');
}
return;
}
} catch (\Exception $e) {
}
}
}
unset($p);
\Phar::unlinkArchive($this->file . '.zip');
}
if (isset($this->tar)) {
if (file_exists($this->file . '.zip')) {
\Phar::unlinkArchive($this->file . '.zip');
unlink($this->file . '.zip');
}
$this->zip = $this->tar->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
if ($this->outfile) {
copy($this->file . '.zip', $this->outfile . '.zip');
}
$this->tar = new \PharData($this->file . '.tar');
return;
}
if (isset($this->tgz)) {
if (file_exists($this->file . '.zip')) {
\Phar::unlinkArchive($this->file . '.zip');
unlink($this->file . '.zip');
}
$this->zip = $this->tgz->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
if ($this->outfile) {
copy($this->file . '.zip', $this->outfile . '.zip');
}
$this->tgz = new \PharData($this->file . '.tgz');
return;
}
// by process of elimination, the phar is in phar format
if (file_exists($this->file . '.zip')) {
\Phar::unlinkArchive($this->file . '.zip');
unlink($this->file . '.zip');
}
$this->zip = $this->phar->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
if ($this->outfile) {
copy($this->file . '.zip', $this->outfile . '.zip');
}
$this->phar = new \Phar($this->file . '.phar');
}