Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36616 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 986 invoked from network); 27 Mar 2008 14:08:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2008 14:08:04 -0000 Authentication-Results: pb1.pair.com header.from=lars@strojny.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lars@strojny.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain strojny.net designates 85.10.204.248 as permitted sender) X-PHP-List-Original-Sender: lars@strojny.net X-Host-Fingerprint: 85.10.204.248 milch.schokokeks.org Received: from [85.10.204.248] ([85.10.204.248:44842] helo=milch.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/76-02016-24AABE74 for ; Thu, 27 Mar 2008 09:08:03 -0500 Received: from [10.22.2.150] (colt-d53d2146.colt.mediaventures.de [::ffff:213.61.33.70]) (AUTH: PLAIN lars@schokokeks.org, SSL: TLSv1/SSLv3,256bits,CAMELLIA256-SHA) by milch.schokokeks.org with esmtp; Thu, 27 Mar 2008 15:07:59 +0100 id 0000000000020003.0000000047EBAA40.00007A4B To: Benjamin Schulz Cc: internals Mailing List In-Reply-To: References: Date: Thu, 27 Mar 2008 15:07:58 +0100 Message-ID: <1206626878.7434.56.camel@localhost> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_milch.schokokeks.org-31307-1206626880-0001-2" X-Mailer: Evolution 2.22.0 Subject: Re: [PHP-DEV] phar API From: lars@strojny.net (Lars Strojny) --=_milch.schokokeks.org-31307-1206626880-0001-2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Benjamin, Am Donnerstag, den 27.03.2008, 14:34 +0100 schrieb Benjamin Schulz: > Hi, > i just read the phar examples in the manual and found things like this: [...] > 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. ArrayAccess is not hackish per se, but it just does not feels right for working with archives. [...] > $p =3D new Phar('coollibrary.phar'); >=20 > /* What about creating a non-static pendant to canWrite()? > Maybe there is an archive file that has only read permissions on =20 > the filesystem or > phar will be able to generate readonly-archives later? (Might be =20 > interesting for companies that want to provide readonly and signed archi= ves for =20 > the customers) > if ($p->canWrite()) { > // Create a file instance > $hugeFile =3D $p->createFile(); >=20 > $fp =3D fopen('hugefile.dat', 'rb'); >=20 > // Set the content > $hugeFile->setContent($fp); (or maybe even =20 > 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(); > } >=20 > // add the file to the archive > $p->addFile($hugeFile, 'data/hugefile.dat'); > // another option would be to pass the file path to the =20 > createFile() method and > // implicitely create it in the archive > $indexPhp =3D $p->createFile('index.php'); > $indexPhp->setContent(...); > } >=20 I second your proposal, but a bit more flexible: // Creating files $phar =3D new Phar(); $file =3D $phar->createFile('/filename'); =EF=BB=BF// Phar acts as a factor= y and returns an object PharFile or something $file->setContent('string'); // Polymorph signature, can either take a stri= ng ... $file->setContent(fopen('file', 'r')); // ... or a resource $file->setContent('foo', $data); // ... or a string and data $file->setContent('bar', array('line1', 'line2')); // ... or an array of li= nes $file->setContent('baz', fopen('file', 'r')); // ... or a name and a resour= ce if (!$phar->isReadonly()) { $phar->save(); // Writes the newly create file to the filesystem } $phar =3D new Phar(); $phar->add('foo'); $phar->add('bar', $data); $phar->add(new SplFileInfo('bar')); Creating directories: $phar =3D new Phar(); $dir =3D $phar->createDirectory('/foo'); // Return PharDirectory object $dir->add(new DirectoryIterator("mydir")); // Adds every file in the direct= ory mydir $dir->add(new RecursiveDirectoryIterator('otherdir')); // Adds every item r= ecursivly $dir->add(new SplFile("foo")); // Adds the file foo $dir->add('bar'); // Adds bar $dir->add('baz', $data) $file =3D $dir->createFile('bla') $file->setContent($data); $dir2 =3D $dir->createDirectory('foo'); ... $phar->save(); No, with fluent interfaces: $phar =3D new Phar(); $phar->createDirectory('foo') ->add('foo') ->add(new SplFileInfo('bar')) ->add('baz', $data); $phar->save(); if PharFile would include a reference to the original Phar object, the last Phar::save() could even be included in the chain. About compression: I would prefer to have Phar::setCompression(Phar::GZIP) or something similiar. Or even Phar::setCompressionStrategy(PharCompressionInterface $interface) but I have the feeling that would go too far :-) cu, Lars --=_milch.schokokeks.org-31307-1206626880-0001-2 Content-Type: application/pgp-signature; name="signature.asc" Content-Transfer-Encoding: 7bit Content-Description: Dies ist ein digital signierter Nachrichtenteil -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (GNU/Linux) iQIcBAABAgAGBQJH66o+AAoJECQPF+sCY6wHY+MP/2Hig5t8qwiOstYo426mwX6d yuTs1pf+rcP13E2F/WJm7klDt4ZfIveF/wjTf6TTl6fkMHFT0kz0IuZEhIz9seUy S21Ge33WZcqwoRKI4p1crlZq5ULFwXzjEawBvoNpfB0StylmjPdInWGNvMxH18cq /2k9rZwNxPw0ZWpqpLsAZUpiFZeRTjHu62Q2Sm42bggPk4uipiSCvpnQQewnuiE2 6YfchHC4/m2hdCxRelGsqCY2+6aS3qsGKwPRtqnIvEdasGLJItb+cARSo9f9Hicx MbJgxSFe+H8vXA/mxJKfe/lxbMHI6sdAfiLguq/k2riuxJTlPvf92LFe+mCweCOF +TDrU2+5bQSe5D6DT40L5ro5tazkuS3wVwZz/pO5HQ0M7G9e3N4eqAP3tJNSuc4m TTITq+Z981DwYHzRjmDR17xY2O8NJx0LtfDQ/Q65GtgIb3834S0Q+iUoMdYpBVlD 3NC0HaS9N1Weqz25KHAjfc8cLr/dQyTP/LM1kQ3YCHRUHlRbq23ikwaMlk7oJqx5 Wl9l/zGwNWDhmp4o6YhVY7HF+TEHE1zaZY/5N76FwK/eIC7NZFbxrxyME85Untwv AAF+f3/j0/n6YZ2dasgAiDU5JDigv8tsnr2lcT6fBLCrhOGaeCfayOmyPVxFhWG4 aKK8S55JHqRlSw/o0QFN =RODq -----END PGP SIGNATURE----- --=_milch.schokokeks.org-31307-1206626880-0001-2--