# phar API update

- Thread: https://externals.io/message/36909
- Original archive: https://news-web.php.net/php.internals/36909
- Started by Gregory Beaver on 2008-04-09T19:30:26+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36909 — Gregory Beaver — 2008-04-09T19:30:26+00:00

URL: https://externals.io/message/36909#36909

Hi,

I've just implemented these features:

1) new getContents() method allows directly retrieving file contents. 
Here is a full-circle example:
<?php
$phar = new Phar('blah.phar');
$phar['a.txt'] = 'hi';
echo $phar['a.txt']->getContents();
?>

2) addFile/addEmptyDir/addFromString.  API is identical to ext/zip
<?php
$phar = new Phar('blah.phar');
$phar->addEmptyDir('hello');
var_dump($phar['hello']->isDir());
$phar->addFile('/path/to/file.txt');
var_dump($phar['/path/to/file.txt']->getContents());
$phar->addFile('/path/to/file.txt', 'file.txt');
var_dump($phar['file.txt']->getContents());
$phar->addFromString('localname.txt', 'hi');
var_dump($phar['localname.txt']);
?>

Still left to do:

1) fix up conversion/compression and decide how best to do this
2) buildFromDirectory (Steph)

Not going to do:

1) $phar['access']['directory']['this']['way']

Greg
