public function archive($name = null, $result = null)
{
if (ini_get('phar.readonly') == '1') {
throw new RuntimeException('set phar.readonly = 0 in php.ini');
}
$from = $name;
$to = $name;
if ($result) {
$from = $name;
$to = $result;
}
$path = $this->_toPath($to);
if (file_exists("{$path}.phar")) {
if (!$this->force) {
$this->error(basename($path) . ".phar already exists in " . dirname($path));
return false;
}
Phar::unlinkArchive("{$path}.phar");
}
try {
$archive = new Phar("{$path}.phar");
} catch (Exception $e) {
$this->error($e->getMessage());
return false;
}
$result = null;
$from = $this->_toPath($from);
if (is_dir($from)) {
$result = (bool) $archive->buildFromDirectory($from, $this->filter);
}
if (file_exists("{$path}.phar.gz")) {
if (!$this->force) {
$this->error(basename($path) . ".phar.gz already exists in " . dirname($path));
return false;
}
Phar::unlinkArchive("{$path}.phar.gz");
}
if ($result) {
$archive->compress(Phar::GZ);
$this->out(basename($path) . ".phar.gz created in " . dirname($path) . " from {$from}");
return true;
}
$this->error("Could not create archive from {$from}");
return false;
}
public function testArchiveNoLibrary() { $this->skipIf(!extension_loaded('zlib'), 'The zlib extension is not loaded.'); $this->skipIf(ini_get('phar.readonly') == '1', 'INI setting phar.readonly = On'); chdir('new'); $app = new Library(array('request' => new Request(), 'classes' => $this->classes)); $app->library = 'does_not_exist'; $result = $app->archive(); $this->assertTrue($result); $path = realpath($this->_testPath); $expected = "new.phar.gz created in {$path} from {$path}/new\n"; $result = $app->response->output; $this->assertEqual($expected, $result); Phar::unlinkArchive($this->_testPath . '/new.phar'); Phar::unlinkArchive($this->_testPath . '/new.phar.gz'); $this->_cleanUp('tests/new'); rmdir($this->_testPath . '/new'); }