Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36615 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90755 invoked from network); 27 Mar 2008 13:34:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2008 13:34:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@benjaminschulz.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@benjaminschulz.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain benjaminschulz.com from 80.81.249.139 cause and error) X-PHP-List-Original-Sender: php@benjaminschulz.com X-Host-Fingerprint: 80.81.249.139 mx.systisoft.com Linux 2.5 (sometimes 2.4) (4) Received: from [80.81.249.139] ([80.81.249.139:33301] helo=mx.systisoft.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/44-02016-852ABE74 for ; Thu, 27 Mar 2008 08:34:18 -0500 Received: (qmail 1659 invoked from network); 27 Mar 2008 13:31:42 -0000 Received: from unknown (HELO mail.ih.systisoft.com) (80.81.249.133) by mx.systisoft.com with SMTP; 27 Mar 2008 13:31:42 -0000 Received: from localhost (localhost [127.0.0.1]) by mail.ih.systisoft.com (Postfix) with ESMTP id D00804B7347 for ; Thu, 27 Mar 2008 14:34:14 +0100 (CET) Received: from mail.ih.systisoft.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00794-08 for ; Thu, 27 Mar 2008 14:34:09 +0100 (CET) Received: from [10.0.150.10] (unknown [10.0.150.10]) by mail.ih.systisoft.com (Postfix) with ESMTP id 621E84B7325 for ; Thu, 27 Mar 2008 14:34:09 +0100 (CET) Message-ID: To: internals Mailing List Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Date: Thu, 27 Mar 2008 14:34:06 +0100 X-Mailer: Apple Mail (2.919.2) X-Virus-Scanned: by amavisd-new at mail.ih.systisoft.com X-Spam-Status: No, hits=-0.702 tagged_above=-999 required=5 tests=ALL_TRUSTED, AWL, BAYES_50, MISSING_SUBJECT, NO_RECEIVED X-Spam-Level: Subject: phar API From: php@benjaminschulz.com (Benjamin Schulz) 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