Skip to content

Commit 7828042

Browse files
authored
[PHP] Add basic php build support (#86)
## Summary * Uses php dev server * looks for `public/index.php` ## How was it tested? * `devbox build examples/php` * unit test
1 parent e7a0032 commit 7828042

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

planner/php_planner.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
"path/filepath"
1111
"strings"
12+
13+
"go.jetpack.io/devbox/boxcli/usererr"
1214
)
1315

1416
// https://github.com/NixOS/nixpkgs/tree/nixos-22.05/pkgs/development/interpreters/php
@@ -32,17 +34,33 @@ func (g *PHPPlanner) Name() string {
3234
}
3335

3436
func (g *PHPPlanner) IsRelevant(srcDir string) bool {
35-
return fileExists(filepath.Join(srcDir, "composer.lock"))
37+
return fileExists(filepath.Join(srcDir, "composer.lock")) ||
38+
fileExists(filepath.Join(srcDir, "composer.json"))
3639
}
3740

3841
func (g *PHPPlanner) GetPlan(srcDir string) *Plan {
3942
v := g.version(srcDir)
40-
return &Plan{
43+
plan := &Plan{
4144
DevPackages: []string{
4245
fmt.Sprintf("php%s", v.majorMinorConcatenated()),
4346
fmt.Sprintf("php%sPackages.composer", v.majorMinorConcatenated()),
4447
},
48+
RuntimePackages: []string{
49+
fmt.Sprintf("php%s", v.majorMinorConcatenated()),
50+
fmt.Sprintf("php%sPackages.composer", v.majorMinorConcatenated()),
51+
},
52+
}
53+
if !fileExists(filepath.Join(srcDir, "public/index.php")) {
54+
return plan.WithError(usererr.New("Can't build. No public/index.php found."))
55+
}
56+
57+
plan.InstallStage = &Stage{
58+
Command: "composer install --no-dev --no-ansi",
59+
}
60+
plan.StartStage = &Stage{
61+
Command: "php -S 0.0.0.0:8080 -t public",
4562
}
63+
return plan
4664
}
4765

4866
func (g *PHPPlanner) version(srcDir string) *version {

testdata/php/php8.1/composer.json

Whitespace-only changes.

testdata/php/php8.1/plan.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"dev_packages": [
3+
"php81",
4+
"php81.Packages.composer"
5+
],
6+
"runtime_packages": [
7+
"php81",
8+
"php81.Packages.composer"
9+
],
10+
"install_stage": {
11+
"command": "composer install --no-dev --no-ansi"
12+
},
13+
"build_stage": {},
14+
"start_stage": {
15+
"command": "php -S 0.0.0.0:8080 -t public"
16+
}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo 'Hello world';

0 commit comments

Comments
 (0)