Skip to content

Commit 816ba5b

Browse files
committed
Add proper php formatting (only on github actions, not locally)
1 parent f872d9f commit 816ba5b

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

.github/workflows/format.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ jobs:
2929
- name: Format python using black
3030
run: black . --target-version py310
3131
- name: Run prettier
32-
run: npm run prettier -- . -w
32+
run: |
33+
python3 http/php/.preformat.py
34+
npm run prettier -- . -w
35+
python3 http/php/.postformat.py
36+
npm run prettier -- . -w
3337
3438
- name: Commit and push changes if any
3539
run: |

http/php/.htaccess

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Files ".*format.py">
2+
Require all denied
3+
</Files>

http/php/.postformat.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import re
3+
4+
for dir, subdirs, files in os.walk("."):
5+
for file in files:
6+
if file.endswith(".php___format__.html"):
7+
with open(os.path.join(dir, file), "rb") as f:
8+
php = f.read().decode()
9+
php = re.sub(r"[ \t]*<\?php", "<?php", php)
10+
with open(os.path.join(dir, file), "wb") as f:
11+
f.write(php.encode())
12+
13+
os.replace(
14+
os.path.join(dir, file),
15+
os.path.join(dir, file.removesuffix("___format__.html")),
16+
)

http/php/.preformat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
for dir, subdirs, files in os.walk("."):
4+
for file in files:
5+
if file.endswith(".html") or file.endswith(".php"):
6+
os.replace(
7+
os.path.join(dir, file), os.path.join(dir, file + "___format__.html")
8+
)

http/php/input.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<title>PHP Input</title>
4+
</head>
5+
<body>
6+
<form action="#" method="POST">
7+
<input type="text" name="text" placeholder="Text input" />
8+
<button>Submit</button>
9+
</form>
10+
<span style="color: #f00">
11+
<?php echo $_POST["text"]; ?>
12+
</span>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)