Skip to content

Commit 79e5940

Browse files
committed
更新 run 指令
可指定php运行版本
1 parent dd3ec67 commit 79e5940

14 files changed

Lines changed: 57 additions & 205 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ composer.phar
1313
log/
1414
worker/vendor
1515
worker/composer.lock
16+
.codebuddy
1617

1718
# Ignore binary output folders
1819
bin/

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
💕 大 部 分 编 程 功 能 都 是 PHP 本 身 不 用 担 心 要 逃 离 舒 适 圈
88

99
- 编译cli项目 编译为单个可执行文件(方便分发)
10-
- 运行FPM项目 使用cli模式运行FPM项目
1110
- php版本管理 可以安装多个php版本,并在项目中切换使用
1211

1312
```sh
@@ -18,14 +17,14 @@
1817
/_.___/_/ /_/\__, (_) .___/_/ /_/ .___/
1918
/____/ /_/ /_/
2019

21-
Bny: v0.0.1 PHP: 已安装 Composer: 已安装 2025-07-19 09:50:12
20+
Bny: v0.0.3 PHP: 已安装 Composer: 已安装 2025-07-19 09:50:12
2221

2322
用法:
2423
bny <指令> [参数] [选项]
2524

2625

2726
指令:
28-
worker 运行FPM项目
27+
run 运行主程序
2928
php 运行PHP
3029
composer 运行Composer
3130
compile 编译项目
@@ -45,7 +44,7 @@ Bny: v0.0.1 PHP: 已安装 Composer: 已安装 2025-07-19 09:50:12
4544

4645
- windows x86_64
4746

48-
- linux x86_64、arrch64(测试)
47+
- linux x86_64、arrch64
4948

5049
### Linux 要求
5150

script/cli.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fn main() {
1313
}
1414
mut args := os.args.clone()
1515
args[0] = 'index.php'
16+
if os.is_file("./php.ini"){
17+
args << ["-c","./php.ini"]
18+
}
1619
mut process := os.new_process(file)
1720
process.set_args(args)
1821
process.run()

script/win32.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ fn main() {
1212
}
1313
mut args := os.args.clone()
1414
args[0] = 'index.php'
15+
if os.is_file("./php.ini"){
16+
args << ["-c","./php.ini"]
17+
}
1518
mut process := os.new_process(file)
1619
process.set_args(args)
1720
process.create_no_window = true // 不显示窗口

src/base.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mut:
1414
pub struct Info {
1515
pub mut:
1616
name string = 'bny'
17-
version string = 'v0.0.2'
17+
version string = 'v0.0.3'
1818
php int = -1
1919
php_list []Phplist
2020
}

src/compile/appimage.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ fn create_project() ! {
4343
mut apprun_file := []string{}
4444
apprun_file << '#! /usr/bin/env bash'
4545
apprun_file << 'dir=$(dirname $(realpath $0))'
46-
apprun_file << 'exec \$dir"/usr/bin/php" \$dir"/usr/bin/${main_filename_ext}" $@'
46+
apprun_file << 'ini_file=\$dir"/usr/bin/php.ini"'
47+
apprun_file << 'if [[ -f "\$ini_file" ]]; then'
48+
apprun_file << ' exec \$dir"/usr/bin/php" -c \$ini_file \$dir"/usr/bin/${main_filename_ext}" $@'
49+
apprun_file << 'else'
50+
apprun_file << ' exec \$dir"/usr/bin/php" \$dir"/usr/bin/${main_filename_ext}" $@'
51+
apprun_file << 'fi'
4752
os.write_file(base.path_add(dir, 'AppRun'), apprun_file.join('\n'))!
4853

4954
// 配置文件

src/files.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn path_php_cli() string {
4545
path += '/windows/x86_64/cli'
4646
} else if os.user_os() == 'linux' {
4747
path += '/linux/${base.get_machine()}/cli'
48+
}else {
49+
path += '/macos/${base.get_machine()}/cli'
4850
}
4951
return path
5052
}

src/run/check.v

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/run/help.v

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,45 @@ pub fn new_args() ![]string {
1818
panic('请指定目标')
1919
}
2020
if arg == '.' {
21-
if os.is_file(base.path_add(os.getwd(), 'bny.config.json')) {
22-
args[0] = base.path_add(Worker{}.dir, 'run.php')
23-
args.insert(1, base.path_add(os.getwd(), 'bny.config.json'))
24-
} else {
25-
args[0] = 'index.php'
21+
args[0] = 'index.php'
22+
}
23+
for i, v in args {
24+
if v == '-v' {
25+
if args[i+1] != '' {
26+
args.delete(i+1)
27+
}
28+
args.delete(i)
29+
break
2630
}
2731
}
2832
return args
2933
}
3034

35+
/**
36+
* 获取php解析器文件路径
37+
*
38+
* @return ! string
39+
*/
40+
pub fn get_php_path() !string {
41+
info := base.get_info()!
42+
args := base.get_args()
43+
ver := cmdline.option(args, '-v', info.php_list[info.php].name)
44+
mut index := -1
45+
for k, v in info.php_list {
46+
if v.name == ver {
47+
index = k
48+
break
49+
}
50+
}
51+
ext := if os.user_os() == 'windows' { '.exe' } else { '' }
52+
return base.path_add(info.php_list[index].path, 'php' + ext)
53+
}
54+
55+
/**
56+
* 帮助查看
57+
*
58+
* @return !
59+
*/
3160
pub fn help() ! {
3261
info := base.get_info()!
3362
mut arr := []string{}
@@ -37,17 +66,9 @@ pub fn help() ! {
3766
arr << ''
3867
arr << term.yellow('目标:')
3968
arr << ''
40-
arr << term.blue(' [file] ') + 'index.php 入口文件'
69+
arr << term.blue(' [file] ') + '入口文件'
70+
arr << term.blue(' -v [number] ') + '指定PHP版本号'
4171
arr << term.blue(' -h ') + '帮助查看'
4272
arr << ''
43-
arr << term.yellow('指令:') + term.dim('Linux 指令')
44-
arr << ''
45-
arr << term.blue(' start ') + '启动服务'
46-
arr << term.blue(' stop ') + '停止服务'
47-
arr << term.blue(' restart ') + '重启服务'
48-
arr << term.blue(' status ') + '查看服务状态'
49-
arr << term.blue(' reload ') + '重新加载服务'
50-
arr << term.blue(' connections ') + '查看连接数'
51-
arr << ''
5273
println(arr.join('\n'))
5374
}

src/run/worker.v

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ import php
44
import os
55
import base
66

7-
struct Worker {
8-
dir string = base.path_add(base.app_path(), 'worker')
9-
}
10-
117
pub fn run() ! {
12-
check_composer()!
8+
php.checked()!
139
mut args := base.get_args()
1410
args.delete(0)
1511

1612
if args.len == 0 || args[0] == '-h' {
1713
help()!
1814
} else {
19-
php_path := php.get_php_path()!
15+
php_path := get_php_path()!
2016
mut process := os.new_process(php_path)
2117
new_arg := new_args()!
2218
process.set_args(new_arg)

0 commit comments

Comments
 (0)