本文整理汇总了PHP中Archive类的典型用法代码示例。如果您正苦于以下问题:PHP Archive类的具体用法?PHP Archive怎么用?PHP Archive使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Archive类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Sets up test case
*
*/
public function setUp()
{
try {
$this->classname = $this->testClassName();
$this->interfacename = $this->testClassName('I');
} catch (IllegalStateException $e) {
throw new PrerequisitesNotMetError($e->getMessage());
}
// Create an archive
$this->tempfile = new TempFile($this->name);
$archive = new Archive($this->tempfile);
$archive->open(ARCHIVE_CREATE);
$this->add($archive, $this->classname, '
uses("util.Comparator", "' . $this->interfacename . '");
class ' . $this->classname . ' extends Object implements ' . $this->interfacename . ', Comparator {
public function compare($a, $b) {
return strcmp($a, $b);
}
}
');
$this->add($archive, $this->interfacename, 'interface ' . $this->interfacename . ' { } ');
$archive->create();
// Setup classloader
$this->classloader = new ArchiveClassLoader($archive);
ClassLoader::getDefault()->registerLoader($this->classloader, TRUE);
}
示例2: create
public function create($paths, $filename = FALSE)
{
$archive = new Archive('tar');
foreach ($paths as $set) {
$archive->add($set[0], $set[1]);
}
$gzfile = bzcompress($archive->create());
if ($filename == FALSE) {
return $gzfile;
}
if (substr($filename, -8) !== '.tar.bz2') {
// Append tar extension
$filename .= '.tar.bz2';
}
// Create the file in binary write mode
$file = fopen($filename, 'wb');
// Lock the file
flock($file, LOCK_EX);
// Write the tar file
$return = fwrite($file, $gzfile);
// Unlock the file
flock($file, LOCK_UN);
// Close the file
fclose($file);
return (bool) $return;
}
示例3: readingArchiveV1
public function readingArchiveV1()
{
$a = new Archive($this->getClass()->getPackage()->getResourceAsStream('v1.xar'));
$a->open(ARCHIVE_READ);
$this->assertEquals(1, $a->version);
$this->assertTrue($a->contains('contained.txt'));
$this->assertEntries($a, array('contained.txt' => "This file is contained in an archive!\n"));
}
示例4: perform
/**
* Execute action
*
* @return int
*/
public function perform()
{
$this->archive->open(ARCHIVE_READ);
$args = $this->getArguments();
if (!isset($args[0]) || !file_exists(current($args))) {
throw new IllegalArgumentException('No archive to compare given or not found.');
}
$cmp = new Archive(new File(current($args)));
$cmp->open(ARCHIVE_READ);
return $this->compare($this->archive, $cmp);
}
示例5: archive
public function archive($build = FALSE)
{
if ($build === 'build') {
// Load archive
$archive = new Archive('zip');
// Download the application/views directory
$archive->add(APPPATH . 'views/', 'app_views/', TRUE);
// Download the built archive
$archive->download('test.zip');
} else {
echo html::anchor(Router::$current_uri . '/build', 'Download views');
}
}
示例6: scanDeployments
/**
* Get a list of deployments
*
* @return remote.server.deploy.Deployable[]
*/
public function scanDeployments()
{
clearstatcache();
$this->changed = FALSE;
while ($entry = $this->folder->getEntry()) {
if (!preg_match($this->pattern, $entry)) {
continue;
}
$f = new File($this->folder->getURI() . $entry);
if (isset($this->files[$entry]) && $f->lastModified() <= $this->files[$entry]) {
// File already deployed
continue;
}
$this->changed = TRUE;
$ear = new Archive(new File($this->folder->getURI() . $entry));
try {
$ear->open(ARCHIVE_READ) && ($meta = $ear->extract('META-INF/bean.properties'));
} catch (Throwable $e) {
$this->deployments[$entry] = new IncompleteDeployment($entry, $e);
continue;
}
$prop = Properties::fromString($meta);
$beanclass = $prop->readString('bean', 'class');
if (!$beanclass) {
$this->deployments[$entry] = new IncompleteDeployment($entry, new FormatException('bean.class property missing!'));
continue;
}
$d = new Deployment($entry);
$d->setClassLoader(new ArchiveClassLoader($ear));
$d->setImplementation($beanclass);
$d->setInterface($prop->readString('bean', 'remote'));
$d->setDirectoryName($prop->readString('bean', 'lookup'));
$this->deployments[$entry] = $d;
$this->files[$entry] = time();
delete($f);
}
// Check existing deployments
foreach (array_keys($this->deployments) as $entry) {
$f = new File($this->folder->getURI() . $entry);
if (!$f->exists()) {
unset($this->deployments[$entry], $this->files[$entry]);
$this->changed = TRUE;
}
delete($f);
}
$this->folder->close();
return $this->changed;
}
示例7: on_download
private function on_download()
{
Util::json_fail(Util::ERR_DISABLED, 'download disabled', !$this->context->query_option('download.enabled', false));
$as = $this->request->query('as');
$type = $this->request->query('type');
$base_href = $this->request->query('baseHref');
$hrefs = $this->request->query('hrefs');
$archive = new Archive($this->context);
set_time_limit(0);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $as . '"');
header('Connection: close');
$ok = $archive->output($type, $base_href, $hrefs);
Util::json_fail(Util::ERR_FAILED, 'packaging failed', !$ok);
exit;
}
示例8: __construct
public function __construct(\ZipArchive $zipArchive, $tmpFilePath = '/tmp')
{
$tmpFile = tempnam($tmpFilePath, 'zip');
parent::__construct($zipArchive, $tmpFile);
register_shutdown_function(function ($filename) {
unlink($filename);
}, $tmpFile);
}
示例9: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
*
* @param
* integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Archive::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例10: unzip
public function unzip($file)
{
$fh = Loader::helper('file');
$dirBase = parent::unzip($file);
$dirFull = $this->getArchiveDirectory($dirBase);
$dirBase = substr(strrchr($dirFull, '/'), 1);
return $fh->getTemporaryDirectory() . '/' . $file . '/' . $dirBase;
}
示例11: afterSaved
public function afterSaved($payload)
{
unset($payload->attributes['created_at']);
unset($payload->attributes['updated_at']);
unset($payload->original['created_at']);
unset($payload->original['updated_at']);
if ($payload->attributes != $payload->original) {
Archive::create(['token' => md5(time()), 'entity_id' => $payload->attributes['id'], 'entity_type' => get_class($payload), 'entity_data' => json_encode($payload->attributes)]);
Log::info(get_class($payload) . ' #' . $payload->attributes['id'] . ' was archived');
}
}
示例12: testAddDirectory
/**
*
*/
public function testAddDirectory()
{
// create test files
$dir = sys_get_temp_dir() . '/testarchive';
$zipfile = sys_get_temp_dir() . '/testarchive.zip';
mkdir($dir);
file_put_contents($dir . '/one.txt', 'one1');
file_put_contents($dir . '/two', 'two2');
mkdir($dir . '/sub');
file_put_contents($dir . '/sub/three.txt', 'three3');
$zip = new Archive();
$zip->open($zipfile, \ZipArchive::CREATE);
$zip->addDirectory($dir);
$zip->close();
$zip = new Archive();
$zip->open($zipfile);
$this->assertEquals('one1', $zip->getFromName('one.txt'));
$this->assertEquals('two2', $zip->getFromName('two'));
$this->assertEquals('three3', $zip->getFromName('sub' . DIRECTORY_SEPARATOR . 'three.txt'));
$zip->close();
// clean up
unlink($dir . '/sub/three.txt');
rmdir($dir . '/sub');
unlink($dir . '/two');
unlink($dir . '/one.txt');
rmdir($dir);
unlink($zipfile);
}
示例13: finalize
public function finalize($totalSize, $treeHash)
{
$file = $this->getFile('data');
if (($f = fopen($file, 'r+')) === false) {
return false;
}
ftruncate($f, $totalSize);
fclose($f);
$a = new Archive(true, $this->vault);
$a->setParam('SHA256TreeHash', $treeHash);
$a->setParam('Size', $totalSize);
$a->setParam('Description', $this->getParam('Description'));
rename($this->getFile('data'), $a->getFile('data'));
$this->delete();
return $a;
}
示例14: codiad_CFG
public function codiad_CFG($hash)
{
$dir_relative = GlobalMas::$filesPath_relative . $hash . "/";
$dir = GlobalMas::$filesPath_absolute . $hash . "/";
//-----------------------------------------------------
if (!file_exists($dir . "codiad")) {
Archive::extract(GlobalMas::$filesPath_absolute . "/codiad.zip", $dir);
//-----------------------------------------------------
$config_contents = FileFolder::file_get_contents($dir . "codiad/config.php");
$config_contents = str_replace("{BASE_PATH}", $dir . "codiad", $config_contents);
$config_contents = str_replace("{BASE_URL}", GenFun::get_full_url($dir . "codiad"), $config_contents);
FileFolder::file_put_contents($dir . "codiad/config.php", $config_contents);
//---------------------------------------------------------
exec("ln -s " . $dir . "compile " . $dir . "codiad/workspace/compile" . " 2>&1", $output);
exec("ln -s " . $dir . " " . $dir . "codiad/workspace/root" . " 2>&1", $output);
//---------------------------------------------------------
if (strpos(join($output), "Errno::") !== false) {
krumo($output);
die;
}
}
}
示例15: previewPlan
function previewPlan(&$user, $plan)
{
$timestamp = mktime();
/* format the journalled plan */
if ($this->getPreference('journal')) {
if (!($divider = $this->getPreference('journal_divider'))) {
$divider = PW_DIVIDER;
}
if ($this->getPreference('journal_order') == 'new') {
// show current plan
$tmp = Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n";
// show archived plans
for ($i = 0; $i < $this->getPreference('journal_entries'); $i++) {
list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i);
if ($ts == 0) {
break;
}
$tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n";
$tmp .= $txt . "\n";
}
$plan = $tmp;
} else {
$tmp = '';
for ($i = $this->getPreference('journal_entries') - 1; $i >= 0; $i--) {
list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i);
if ($ts == 0) {
break;
}
$tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n";
$tmp .= $txt . "\n";
}
// show current plan
$tmp .= Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n";
$plan = $tmp;
}
}
return $this->displayPlan($user, $plan);
}