fastadmin打包插件
<?php
namespace app\command; use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output; class Scan extends Command
{
protected $root = 'runtime/';
protected $output = '';
protected $file_count = 0; protected function configure()
{
$this->setName('fa')
->addArgument('name', Argument::OPTIONAL, "插件名称")
->addOption('source', null, Option::VALUE_REQUIRED, '压缩文件')
->setDescription('打包fa开发的插件');
} protected function execute(Input $input, Output $output)
{
$this->output = $output;
$name = trim($input->getArgument('name'));
if (!$name) {
$output->writeln('请输入插件名称:');
exit();
} else {
$this->root .= $name . '/';
}
$this->selectFIles('@plugin ' . $name); if ($input->hasOption('source')) {
$source = $input->getOption('source');
} else {
$source = 'zip';
} $addons = './runtime/addons';
if (!file_exists($addons)) {
$this->mkdirs($addons, 0777);
}
// 拷贝到插件
$addons_path = './addons/' . $name;
$this->recurse_copy($this->root, $addons_path); $this->zip($addons_path, $addons . '/' . $name, $name); $zipcreated = $addons . '/' . $name . ".zip";
if (file_exists($zipcreated)) {
$this->recursiveDelete($this->root);
} $output->writeln('打包成功,共' . $this->file_count . '个文件!');
} //执行,递归查询文件
private function selectFIles($name)
{
//开始运行
$arr_file = array();
$scans = [
'./public',
'./app',
];
foreach ($scans as $key => $value) {
$this->trees($arr_file, $value, str_replace('./', '', $value));
$this->handelFiles($arr_file, $name);
}
} // 递归拿到所有的文件包含目录
private function trees(&$arr_file, $directory, $dir_name = '')
{ $mydir = dir($directory);
while ($file = $mydir->read()) {
if ((is_dir("$directory/$file")) and ($file != ".") and ($file != "..")) {
$this->trees($arr_file, "$directory/$file", "$dir_name/$file");
} else if (($file != ".") and ($file != "..")) {
$arr_file[] = "$dir_name/$file";
}
}
$mydir->close();
} //判断文件是否包含插件标识
private function handelFiles(&$arr_file, $name = '')
{
foreach ($arr_file as $key => $value) {
if (!is_dir($value)) {
// 文件
if (is_file($value)) {
$file = file_get_contents($value);
if (strstr($file, $name)) {
$this->file_count += 1;
$this->makeDirByPath($value);
}
}
}
}
} /**
* 根绝文件路径创建对应的目录
* @param string $path a/b/c/d/
*
*/
private function makeDirByPath($path)
{
$opath = $path;
$path = $this->root . $path;
$dir = dirname($path);
if (!file_exists($dir)) {
$this->mkdirs($dir, 0777);
$this->echo('创建文件夹' . $dir . '成功');
} if (is_file($opath)) {
copy($opath, $path);
$this->echo('拷贝文件' . $opath . '成功');
}
} //创建文件夹
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)) {
return true;
} if (!$this->mkdirs(dirname($dir), $mode)) {
return false;
} return @mkdir($dir, $mode);
} //输出模式
function echo ($msg) {
$this->output->writeln($msg);
} private function zip($pathdir, $names, $addons_name)
{
// 创建压缩目录的名称
$zipcreated = $names . ".zip";
// Get real path for our folder
$rootPath = $pathdir; // Initialize archive object
$zip = new \ZipArchive();
$zip->open($zipcreated, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); // Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootPath),
\RecursiveIteratorIterator::LEAVES_ONLY
); foreach ($files as $name => $file) {
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
// var_dump($addons_name);die;
$relativePath = substr($filePath, strlen($rootPath) + 15 + strlen($addons_name));
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
} // $dir:要删除的文件的目录
private function recursiveDelete($dir)
{
// 打开指定目录
if ($handle = @opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (($file == ".") || ($file == "..")) {
continue;
}
if (is_dir($dir . '/' . $file)) {
// 递归
$this->recursiveDelete($dir . '/' . $file);
} else {
unlink($dir . '/' . $file); // 删除文件
}
}
@closedir($handle);
rmdir($dir);
}
} // cp文件$src 源, $dst目标
private function recurse_copy($src, $dst)
{
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
$this->recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
}
1.php think scan 插件名称
思考:
1.需要插件标识 @plugin 插件名称
2.需要配置文件console.php配置命名行模式
3.打包的文件在./runtime/addons目录
fastadmin打包插件的更多相关文章
- FastAdmin CMS 插件下载
FastAdmin CMS 插件下载 CMS内容管理系统插件(含小程序) 自定义内容模型.自定义单页.自定义表单.自定义会员发布.付费阅读.小程序等 提供全部前后端源代码和小程序源代码 功能特性 基于 ...
- 随笔:关于 FastAdmin ueditor 插件 中的 rand mt_rand mt_getrandmax 问题
随笔:关于 FastAdmin ueditor 插件 中的 rand mt_rand mt_getrandmax 问题 问题来源 一位小伙伴在使用 Ueditor 插件时出错,因为用的是 php7.1 ...
- FastAdmin CMS 插件相关文章收集(2018-08-16)
FastAdmin CMS 插件相关文章收集(2018-08-16) CMS内容管理系统(含小程序) 介绍 https://www.fastadmin.net/store/cms.html CMS内容 ...
- 为什么 FastAdmin 的插件不全部免费?
为什么 FastAdmin 的插件不全部免费? 主要还是有以下几个原因. 支持开发者. 为了支付网站空间费和 CDN 费. 有收入后可以更好的开发 FastAdmin.
- assembly打包插件引发的自定义spring标签找不到声明的错误
异常信息:通配符的匹配很全面, 但无法找到元素 的声明. 报的异常信息是关于我们使用的一个自定义的spring标签,这个异常通常的原因可能是读取不到自定义标签的映射. 到META-INF目录下找一下是 ...
- maven打包插件maven-assembly-plugin
1.POM文件添加jar包生成插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifac ...
- springboot 打包插件去除jar包瘦身
1.pom文件配置 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>s ...
- Maven打包插件Assembly(七)
1. 在 dubbo 的 provider 项目(实现类项目dubbo-service-impl)中 pom.xml 配置 assembly插件信息 <!-- 指定项目的打包插件信息 --> ...
- eclipse打包插件net.sf.fjep.fatjar
eclipse打包插件安装 1)将net.sf.fjep.fatjar_0.0.32.jar拷贝到eclipse安装目录中的plugins目录下,然后重启eclipse即可. 软件获取方式: 链接:h ...
- java 打包插件
是时候闭环Java应用了 原创 2016-08-16 张开涛 你曾经因为部署/上线而痛苦吗?你曾经因为要去运维那改配置而烦恼吗?在我接触过的一些部署/上线方式中,曾碰到过以下一些问题: 1.程序代码 ...
随机推荐
- Beautiful Soup库的安装
安装:'以管理员身份运行'cmd 执行pip install beautifulsoup4 Beautiful Soup库的理解: 解析.遍历.维护标签树的功能库 那么何为标签树? 1 from bs ...
- 肖sir ___性能测试____多线程
一.理论 (一) (1)多线程是Python程序中实现多任务的一种方式(2)线程是程序执行的最小单位. (3)同属一个进程的多个线程共享进程所拥有的全部资源. (二)进程和线程对比 (1)关系对比: ...
- Bugku-不可破译的密码[wp]
一 题目分析 flag.txt cipher.txt (1)密码表形式和维吉尼亚密码一样 (2)看到504Q0304 很容易想到 504B0304 Zip文件头. 二 解题步骤 2.1 解密密文 根据 ...
- Blockchain-enabled Access Control with Fog Nodes for Independent IoTs
摘要: 物联网设备能力有限且数量多,因此当前的传统物联网平台可能无法在可扩展性.可靠性和实时响应方面有效地处理访问控制.本文提出了一种基于区块链.雾节点和物的角色的分散式物联网访问控制系统,利用以太坊 ...
- java中的Filter(过滤器)和Intercepter(拦截器)的认知
一.过滤器的配置 首先,从认知方面看,如果自己真的对Filter和Intercepter 不熟悉或者忘记的话可以自己在IDEA中编写Demo进行查看两个的区别,这也是自己动手去认知的过程.首先从Fil ...
- Centos 7 环境 安装todesk异常
按照todesk官网安装步骤安装. 其实就两步就完成了,在自己虚拟机centos7环境下测试一切正常,但正式环境centos7.9环境下能安装,但安装完打不开,感觉是内核版本的问题. Todesk-- ...
- 星链技术设计(starlink techriage design)
1.星链 定义: 星链,是美国太空探索技术公司的一个项目,太空探索技术公司计划在2019年至2024年间在太空搭建由约1.2万颗卫星组成的"星链"网络提供互联网服务,其中158 ...
- flutter CustomScrollView多个滑动组件嵌套
CustomScrollView是使用Sliver组件创建自定义滚动效果的滚动组件.使用场景: ListView和GridView相互嵌套场景,ListView嵌套GridView时,需要给GridV ...
- 路飞之-后台日志封装-前后端分离的rbac项目演示-全局异常处理封装-封装Response-luffy数据库创建-软件开发模式-User模块用户表-django的配置文件-开启media访问
目录 路飞之-后台日志封装-前后端分离的rbac项目演示-全局异常处理封装-封装Response-luffy数据库创建-软件开发模式-User模块用户表-django的配置文件-开启media访问 今 ...
- Linux下添加启动项并简化操作命令-nginx为例
1.添加nginx为启动项 1. vi /etc/rc.d/rc.local 2.将启动命令直接添加到最后即可 *注:通过下图可知 /etc/rc.d/rc.local和 ...