Skip to content

Commit 365fdab

Browse files
committed
feat: migrated to a Symfony app
1 parent 8e2598e commit 365fdab

File tree

14 files changed

+4325
-80
lines changed

14 files changed

+4325
-80
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
# .gitignore
1+
# .gitignore
2+
/.idea
3+
/var
4+
/vendor

.htaccess

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
Options +FollowSymlinks -MultiViews -Indexes
55

66
# ----------------------------------------------------------------------
7-
# | Rewrite rules for api.phpmyfaq.de |
7+
# | Redirect all requests to public/ (Front Controller) |
88
# ----------------------------------------------------------------------
99
<IfModule mod_rewrite.c>
1010
RewriteEngine On
1111
RewriteBase /
1212

13-
# Handle preflight OPTIONS requests
13+
# Handle preflight OPTIONS requests early
1414
RewriteCond %{REQUEST_METHOD} OPTIONS
1515
RewriteRule ^ - [R=204,L]
1616

17-
# Existing rewrite rules
18-
RewriteRule ^versions$ /version.php [L]
19-
RewriteRule ^version/stable$ /version.php?branch=stable [L]
20-
RewriteRule ^version/development$ /version.php?branch=development [L]
21-
RewriteRule ^version/nightly$ /version.php?branch=nightly [L]
22-
RewriteRule ^verify/(.+)$ /verify.php?version=$1 [L]
17+
# Send everything to public/, keep existing paths
18+
RewriteRule ^public/ - [L]
19+
RewriteRule ^(.*)$ public/$1 [L]
2320
</IfModule>
2421

2522
# ----------------------------------------------------------------------

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ JSON Response:
1818
"nightly_released: "2023-09-21"
1919
}
2020

21-
### api.phpmyfaq.de/verify/&lt;version&gt;
21+
### api.phpmyfaq.de/verify/<version>
2222

2323
JSON Response:
2424

@@ -64,3 +64,40 @@ Requests:
6464
Mozilla Public License 2.0, see LICENSE.md for more information.
6565

6666
Copyright © 2014-2023 Thorsten Rinne
67+
68+
69+
<!-- Added: Symfony-like lightweight front controller + routing -->
70+
71+
## Lightweight Symfony-based front controller
72+
73+
- Front controller: `public/index.php` using `symfony/http-foundation` and `symfony/routing`.
74+
- Controller: `src/Controller/ApiController.php` implements all endpoints.
75+
- Apache rewrites: root `.htaccess` forwards all requests to `public/`, and `public/.htaccess` routes to the front controller.
76+
- CORS support: default `Access-Control-*` headers and `OPTIONS` preflight handling.
77+
78+
### Requirements
79+
- PHP >= 8.2
80+
81+
### Local run
82+
Install deps and start a local server:
83+
84+
```bash
85+
composer install
86+
composer serve
87+
# or
88+
php -S 127.0.0.1:3000 -t public public/index.php
89+
```
90+
91+
Try:
92+
93+
```bash
94+
curl http://127.0.0.1:3000/
95+
curl http://127.0.0.1:3000/versions
96+
curl http://127.0.0.1:3000/version/stable
97+
curl "http://127.0.0.1:3000/verify/2.8.18"
98+
```
99+
100+
### Notes
101+
- Nightly value is generated as `nightly-<yesterday>`; its release date equals yesterday.
102+
- `verify` responds with 418 for missing or invalid versions.
103+
- CORS headers are always present; `OPTIONS` returns 204.

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "thorsten/phpmyfaq-api-app",
3+
"description": "Mini Symfony-based API for phpMyFAQ version and verification endpoints",
4+
"type": "project",
5+
"license": "MPL-2.0",
6+
"authors": [
7+
{
8+
"name": "Thorsten Rinne",
9+
"email": "thorsten@phpmyfaq.de"
10+
}
11+
],
12+
"version": "1.0.0",
13+
"minimum-stability": "stable",
14+
"prefer-stable": true,
15+
"require": {
16+
"php": ">=8.4",
17+
"symfony/http-foundation": "^7.3",
18+
"symfony/routing": "^7.3",
19+
"symfony/framework-bundle": "^7.3"
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "^12.0",
23+
"symfony/phpunit-bridge": "^7.3",
24+
"symfony/browser-kit": "^7.3",
25+
"symfony/dom-crawler": "^7.3"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"App\\": "src/"
30+
}
31+
},
32+
"config": {
33+
"sort-packages": true
34+
},
35+
"scripts": {
36+
"serve": "php -S localhost:3000 -t public",
37+
"test": "vendor/bin/phpunit"
38+
}
39+
}

0 commit comments

Comments
 (0)