Utiliser Phar pour packager un projet : Différence entre versions
De e-glop
(→Construire son archive Phar) |
|||
| Ligne 86 : | Ligne 86 : | ||
Utiliser la constante __DIR__ à la place. | Utiliser la constante __DIR__ à la place. | ||
| + | |||
| + | == e-venement ou un autre projet Symfony1 == | ||
Version du 14 janvier 2016 à 13:17
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]
Si vous avez des répertoires où vous aurez à écrire des données
Utiliser la commande :
Phar::mount('/writable/path/cache/', 'phar://e-venement.phar.php/cache/');
Ainsi, toutes les écritures dans ./cache (dans l'archive) seront envoyées dans /writable/path/cache/ (équivalent d'un mount UNIX).
Placez cette commande (au choix) :
- dans un fichier chargé en début d'exécution de votre application
- dans un fichier que vous aurez créé spécialement et qui sera chargé avant (ou au tout début de) chaque exécution de votre application
- dans un stub de votre archive Phar
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.