Utiliser Phar pour packager un projet
De e-glop
Révision datée du 13 janvier 2016 à 16:16 par BeTa (discussion | contributions) (Page créée avec « == Construire son archive Phar == === Script de construction === Créer un make-archive.php comme suit : <?php $path = './web/e-venement.phar.php'; Phar::unli... »)
Sommaire
Construire son archive Phar
Script de construction
Créer un make-archive.php comme suit :
<?php
$path = './web/e-venement.phar.php';
Phar::unlinkArchive($path);
$phar = new Phar($path, NULL, 'e-venement.phar.php');
$phar->buildFromDirectory($_SERVER['argv'][1]);
$phar->stopBuffering();
/*
Phar::mount('/var/www/dev.libre-informatique.fr/cache/', 'phar://e-venement.phar.php/cache/');
Phar::mount('/var/www/dev.libre-informatique.fr/log/', 'phar://e-venement.phar.php/log/');
*/
Et appelez-le via la commande :
$ php -d phar.readonly=0 make-archive.php [RÉPERTOIRE À PACKAGER]
Les commandes à oublier / remplacer
realpath()
À remplacer par la fonction suivante :
function realpath2($path)
{
// whether $path is unix or not
$unipath = strlen($path)==0 || $path{0}!='/';
$unc = substr($path,0,2)=='\\\\'?true:false;
// attempts to detect if path is relative in which case, add cwd
if(strpos($path,':') === false && $unipath && !$unc){
$path=getcwd().DIRECTORY_SEPARATOR.$path;
if($path{0}=='/'){
$unipath = false;
}
}
// resolve path parts (single dot, double dot and double delimiters)
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if ('.' == $part){
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
// resolve any symlinks
if( function_exists('readlink') && file_exists($path) && linkinfo($path)>0 ){
$path = readlink($path);
}
// put initial separator that could have been lost
$path = !$unipath ? '/'.$path : $path;
$path = $unc ? '\\\\'.$path : $path;
// TODO
$path = str_replace('phar:', 'phar://', $path);
return $path;
}
getcwd()
Utiliser la constante __DIR__ à la place.