Hi,
i just read the phar examples in the manual and found things like this:

$p = new Phar('coollibrary.phar');
if (Phar::canWrite()) {
    $fp = fopen('hugefile.dat', 'rb');
    $p['data/hugefile.dat'] = $fp;
    if (Phar::canCompress()) {
        $p['data/hugefile.dat']->setCompressedGZ();
    }
    $p['images/wow.jpg'] = file_get_contents('images/wow.jpg');
$p['images/wow.jpg']->setMetaData(array('mime-type' => 'image/ jpeg'));
    $p['index.php'] = file_get_contents('index.php');
}

First thing: yes i fully understand what the code is doing but i still think that it doesn't need to be so "hackish". One thing is that i think there is no point in using ArrayAccess here, in my oppinion ArrayAccess is great to hack stuff but it doesn't belong in such (maybe soon?) core functionality. The second thing that looks weird to me is that the setter (offsetSet) sets the file content but the getter (offsetGet) retrieves a file object. What about changing this into something more OO like this (just a proposal):

$p = new Phar('coollibrary.phar');

/* What about creating a non-static pendant to canWrite()?
Maybe there is an archive file that has only read permissions on the filesystem or phar will be able to generate readonly-archives later? (Might be interesting for companies that want to provide readonly and signed archives for the customers)
if ($p->canWrite()) {
    // Create a file instance
    $hugeFile = $p->createFile();

    $fp = fopen('hugefile.dat', 'rb');

    // Set the content
$hugeFile->setContent($fp); (or maybe even setContentResourceHandle(...))
    if (Phar::canCompress()) {
        /* how is the compression implemented? through streamfilters?
           than how about a ->setCompression('bzip')
           that internally resolves to the bzip.(de)compress:// stuff?
        $p['data/hugefile.dat']->setCompressedGZ();
    }

    // add the file to the archive
    $p->addFile($hugeFile, 'data/hugefile.dat');

// another option would be to pass the file path to the createFile() method and
    // implicitely create it in the archive
    $indexPhp = $p->createFile('index.php');
    $indexPhp->setContent(...);
}

Regards,
Benjamin


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to