Browsing this Thread:   1 Anonymous Users






php phar 打包
#1
Just can't stay away
Just can't stay away


See User information
<?php

$exts 
= ['php','css''js' ];    // 需要打包的文件后缀, twig是模版文件, 你还可以安需加入html等后缀
$dir __DIR__;             // 需要打包的目录

$file 'yii.app.out.phar';      // 包的名称, 注意它不仅仅是一个文件名, 在stub中也会作为入口前缀
$phar = new Phar(__DIR__ '/' $fileFilesystemIterator::CURRENT_AS_FILEINFO FilesystemIterator::KEY_AS_FILENAME$file);

// 开始打包
$phar->startBuffering();


// 将后缀名相关的文件打包
foreach ($exts as $ext) {
    
$phar->buildFromDirectory($dir'/.' $ext '$/');
}

// 把build.php本身摘除
$phar->delete('build.php');
$phar->delete('requirements.php');

// 设置入口
$phar->setStub("<?php
Phar::mapPhar('
{$file}');
require 'phar://
{$file}/web/index.php';
__HALT_COMPILER();
?>"
);


$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();

// 打包完成
echo "Finished {$file}n";

#$new_name  = date("Y.md.Hi.") . $file;

rename(__DIR__ '/' $file__DIR__ "/../" $file);

Posted on: 2023/3/31 10:07
Top








friend links
Themes

(2 themes)
Login
Username:

Password:


Lost Password?
Register now!
Categories
Xoops (11)
--Modules (2)
--Themes (0)
Article (8)