Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP ARCHIVE (Phar)

PHP ARCHIVE (Phar)

Bc302e4bfb9e897e01293bb1c54996aa?s=128

Christian Münch

July 21, 2017
Tweet

More Decks by Christian Münch

Other Decks in Programming

Transcript

  1. PHP ARCHIVE Christian Münch / @cmuench 1

  2. Was ist ein Phar Archiv? Phar archives are best characterized

    as a convenient way to group several files into a single file. As such, a phar archive provides a way to distribute a complete PHP application in a single file and run it from that file without the need to extract it to disk. Additionally, phar archives can be executed by PHP as easily as any other file, both on the commandline and from a web server. Phar is kind of like a thumb drive for PHP applications. http://www.php.net/manual/en/intro.phar.php Christian Münch / @cmuench 2
  3. Was ist in einer Phar Datei? ein Stub Ein Manifest,

    welches den Inhalt beschreibt Inhalte Eine Signatur zum Prüfen ob die Datei valide ist (optional) Christian Münch / @cmuench 3
  4. Historie PEAR Paket "PHP_Archive" 25 . Januar 2005 Damals aktuelle

    PHP Version -> 4.3.7 Registrierte phar:// Stream Reiner PHP Code Christian Münch / @cmuench 4
  5. Historie / Phar Reloaded 28.03.2007 PECL Package Implementierung in C

    SPL Integration APC Kompatibilität Damals aktuelle PHP Version 5.2 Christian Münch / @cmuench 5
  6. Status Quo Ab PHP 5.3 (30. Juni 2009) ist das

    Phar Modul in der Standard Distribution enthalten. Christian Münch / @cmuench 6
  7. Datei Formate Phar Tar Zip Bzip Bzip2 Christian Münch /

    @cmuench 7
  8. Feature Matrix Christian Münch / @cmuench 8

  9. Phar Datei erstellen $phar = new Phar('test.phar', 0, 'test.phar'); $phar->buildFromIterator(

    new RecursiveIteratorIterator( new RecursiveDirectoryIterator('src') ), '.' ); $phar->setStub( $phar->createDefaultStub( 'src/cli/index.php', 'src/web/index.php' ) ); Christian Münch / @cmuench 9
  10. Include <?php echo include 'phar://test.phar/src/a.php'; Christian Münch / @cmuench 10

  11. CLI Stub <?php echo include 'phar://test.phar/src/a.php'; __HALT_COMPILER(); Kann z.B. einen

    Autoloader enthalten. Christian Münch / @cmuench 11
  12. Metadaten <?php try { $pharInfo = new \Phar('phar://test.phar'); var_dump($pharInfo->getMetadata()); $pharInfo->setMetadata(array('Created

    at' => 'PHPUG Rheinhessen')); } catch (\Exception $e) { echo $e->getMessage(); } Christian Münch / @cmuench 12
  13. Metadaten (pro Datei) <?php try { $pharFileInfo = new \PharFileInfo('phar://test.phar/src/a.php');

    var_dump($pharFileInfo->getContent()); var_dump($pharFileInfo->getMetadata()); var_dump($pharFileInfo->isCompressed()); $pharFileInfo->setMetadata(array('Created at' => 'PHPUG Rheinhessen')); } catch (\Exception $e) { echo $e->getMessage(); } Christian Münch / @cmuench 13
  14. Komfortables Paketieren Box Phing Christian Münch / @cmuench 14

  15. Box http://box-project.org { "chmod": "0755", "directories": ["src"], "alias": "test.phar", "output":

    "test.phar", "stub": "src/cli/index.php" } Christian Münch / @cmuench 15
  16. Phing http://www.phing.info/ Christian Münch / @cmuench 16

  17. Phing build.xml <?xml version="1.0"?> <project name="phar-create-example" default="dist"> <target name="dist"> <pharpackage

    basedir="${project.basedir}" compression="none" alias="test.phar" destfile="test.phar" clistub="src/cli/index.php" webstub="src/web/index.php" signature="true"> <fileset dir="src"> <include name="**" /> </fileset> </pharpackage> </target> </project> Christian Münch / @cmuench 17
  18. Praxis Beispiele Composer n98-magerun pestl PHPUnit Christian Münch / @cmuench

    18
  19. Danke! Christian Münch / @cmuench 19