/** * */ 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); }
/** * 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); }
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")); }
/** * 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); }
/** * 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; }
public function creatingArchive() { $contents = array('lang/Object.class.php' => 'class Object { }', 'lang/Type.class.php' => 'class Type extends Object { }'); $a = new Archive(new Stream()); $a->open(ARCHIVE_CREATE); foreach ($contents as $filename => $bytes) { $a->addFileBytes($filename, NULL, NULL, $bytes); } $a->create(); $this->assertEntries($a, $contents); }
/** * Constructor * * @param lang.archive.Archive archive * @param string name */ public function __construct(Archive $archive, $name) { $archive->isOpen() || $archive->open(ARCHIVE_READ); $this->archive = $archive; $this->name = $name; }
require_once 'archive.php'; // $base_url = "http://127.0.0.1/devdesktop/archive/"; // $base_url = "http://127.0.0.1/devdesktop/archive/archivist/"; $method = $_SERVER['REQUEST_METHOD']; $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1)); // $request = @$_SERVER['PATH_INFO']; // var_dump($request); if (count($request) > 0) { if ($method === 'GET') { if ($request[0] === 'listar') { array_key_exists('path', $_GET) ? $path = $_GET['path'] : ($path = null); if (Archive::isFolder($path)) { $reponse = ['type' => 'folder', 'data' => Archive::all($path)]; echo json_encode($reponse); } else { $reponse = ['type' => 'file', 'data' => Archive::open($path)]; echo json_encode($reponse); } } if ($request[0] === 'folder') { echo Archive::isFolder($_GET['url']); } } else { if (isset($_POST) && $method === 'POST') { if ($request[0] === 'store') { if (count($_FILES) < 1) { return "O campo arquivo não pode ser vazio."; } return Archive::store($_FILES['arquivo']); } } else {