/** * Get package contents * * @param string package * @return string[] filenames */ public function packageContents($package) { $contents = []; $acquired = \xp\xar::acquire(urldecode(substr($this->archive, 6, -1))); $cmps = strtr($package, '.', '/'); $cmpl = strlen($cmps); foreach (array_keys($acquired['index']) as $e) { if (strncmp($cmps, $e, $cmpl) != 0) { continue; } $entry = 0 != $cmpl ? substr($e, $cmpl + 1) : $e; // Check to see if we're getting something in a subpackage. Imagine the // following structure: // // archive.xar // - tests/ClassOne.class.php // - tests/classes/RecursionTest.class.php // - tests/classes/ng/NextGenerationRecursionTest.class.php // // When this method is invoked with "tests" as name, "ClassOne.class.php" // and "classes/" should be returned (but neither any of the subdirectories // nor their contents) if (false !== ($p = strpos($entry, '/'))) { $entry = substr($entry, 0, $p); if (strstr($entry, '/')) { continue; } $entry .= '/'; } $contents[$entry] = null; } return array_keys($contents); }
<?php namespace xp\test; $test = (require 'test.php'); $path = (require 'path.php'); $xars = (require __DIR__ . '/../../src/xar-support.php'); exit($test->run(['@before' => function () use($path) { $this->lib = $path->compose(__DIR__, '/lib'); }, 'registers xar wrapper' => function () { $this->assertEquals(true, in_array('xar', stream_get_wrappers())); }, 'can handle v1 archives' => function () use($path) { $this->assertEquals(['contained.txt' => [38, 0, 0]], \xp\xar::acquire($path->compose($this->lib, 'v1.xar'))['index']); }, 'can extract v1 archives' => function () use($path) { $this->assertEquals("This file is contained in an archive!\n", file_get_contents('xar://' . $path->compose($this->lib, 'v1.xar') . '?contained.txt')); }, 'can handle v2 archives' => function () use($path) { $this->assertEquals(['contained.txt' => [38, 0, 0]], \xp\xar::acquire($path->compose($this->lib, 'v2.xar'))['index']); }, 'can extract v2 archives' => function () use($path) { $this->assertEquals("This file is contained in an archive!\n", file_get_contents('xar://' . $path->compose($this->lib, 'v2.xar') . '?contained.txt')); }]));