phar better tools
TRANSCRIPT
HOLGER WOLTERSDORFCIO • FATHER • HUSBAND • PHP DEV
ORGA-MITGLIED DER
@hollodotme@phpindd
phpind.de
github.com/hollodotmegithub.com/PHPinDD
1 2 3
Einführung in PHAR Tools
PHARs verteilen & updaten
Anwendungs-Beispiele PhiVE
4
Was sind PHARs eigentlich?๏ PHARs sind (ausführbare) gepackte PHP
Applikationen๏ PHP-eigenes Format, aber konvertierbar
nach ZIP und TAR๏ Kann mit der PHAR Extension oder
PEAR\PHP_Archive erstellt werden๏ Lese-/Schreibzugriff über StreamWrapper
1 Einführung in PHAR Tools
Hallo Welt!
<?php
$phar = new Phar( __DIR__ . '/hello.phar' );$phar->buildFromDirectory( __DIR__ . '/HelloPHAR' );$phar->setDefaultStub( 'bin/main.php' );
/makephar.php
<?php
echo 'Hello World!';
/HelloPHAR/bin/main.php
Einführung in PHAR Tools1
php.ini[Phar]; http://php.net/phar.readonly;phar.readonly = On
; http://php.net/phar.require-hash;phar.require_hash = On
;phar.cache_list =
Einführung in PHAR Tools1
php.ini[Phar]; http://php.net/phar.readonly;phar.readonly = Onphar.readonly = Off
; http://php.net/phar.require-hash;phar.require_hash = On
;phar.cache_list =
Einführung in PHAR Tools1
Einführung in PHAR Tools1
Automate everything!
Einführung in PHAR Tools1
PHAR Tools vs. Tool-Scripts:๏ Kaum Mehraufwand๏ Beliebige Komplexität und Größe๏ Einfach zu verteilen und zu aktualisieren๏ Nicht ohne weiteres manipulierbar๏ Herkunft kann verifiziert werden๏ Dependency Encapsulation
Einführung in PHAR Tools1
Console / Process
BOX Project
DependencyManager
Einführung in PHAR Tools1
Features Symfony Console:๏ Coloured Logging / Verbosity-Levels ๏ App-Struktur / Commands๏ Input / Output Interfaces๏ Optionen und Argumente Handling๏ Diverse Helpers๏ Hilfe
Einführung in PHAR Tools1
Features BOX Project:๏ Einfache Config für das PHAR-Building๏ Placeholder z.B. für GIT-Version๏ Stubbing für CLI Executables๏ Include/Exclude Files๏ Signing / Verifying mit OpenSSL Key
Anwendungs-Beispiele2
Anwendungsbeispiele2
“Standard” PHAR Tools:๏ Testing: phpunit / codecept๏ Analysis: pdepend, phpcpd, phpcs,
phploc, phpmd, …๏ Dependencies: composer, graph-
composer๏ und viele mehr…
Anwendungsbeispiele2
DEMO
PHARs verteilen & updaten3
PHARs verteilen & updaten3
Tipps für die Verteilung:๏ Eigenes Repo für die PHARs๏ Versionierung nach SemVer (ohne “v”!)๏ Permalink für den latest Build๏ Katalog für alle Builds (JSON)
PHARs verteilen & updaten3
Install / Update-Strategien:๏ Self-Hosted๏ GitHub als Download zum Release๏ PhiVE / PHAR.IO
VIELEN DANK!
@hollodotme@phpindd
phpind.de
github.com/hollodotmegithub.com/PHPinDD
www.fortuneglobe.com
www.phpug-dresden.de@phpugdd
HOLGERWOLTERSDORF
slides availableon slideshare
AppendixALinks / Quellen:
๏ Official PHAR documentation: http://php.net/phar๏ Symfony Console Component: http://symfony.com/doc/current/components/console๏ Symfony Process Component: http://symfony.com/doc/current/components/process๏ BOX-Project (GitHub): https://github.com/box-project/box2๏ BOX-Project Documentation: http://box-project.github.io/box2/๏ PHAR-Update Lib: https://packagist.org/packages/herrera-io/phar-update๏ Blog-Post “Distributing a PHP CLI app with ease” by Matthieu Moquet (@MattKetmo):
https://moquet.net/blog/distributing-php-cli/๏ Blog Post “Secure PHAR Automation” by Matthew Weier O’Phinney:
https://mwop.net/blog/2015-12-14-secure-phar-automation.html๏ PHAR Updater:
๏ https://github.com/padraic/phar-updater๏ https://github.com/kherge-abandoned/php-phar-update
๏ Example-Tools: https://github.com/PHPinDD/phar-better-tool-example๏ Example-Distribution: https://github.com/PHPinDD/phar-better-tool-distribution