diff --git a/README.md b/README.md index cbdc735..e333e11 100755 --- a/README.md +++ b/README.md @@ -1,21 +1,29 @@ # miniPHP -A tiny PHP starter project for small websites and personal projects. +A tiny PHP project template for small websites, internal tools, APIs, and personal projects. + +miniPHP is not a framework. + +There is no Composer requirement, no dependency injection container, no ORM, no service providers, and no framework lifecycle to learn. + +Just plain PHP with a simple router, helper functions, optional SQLite support, and a project structure that stays out of your way. + +## Philosophy The goal is simple: -* Clone -* Change git remote -* Start building +1. Clone the repository +2. Run `init_miniphp.sh` +3. Start building -No framework. -No Composer. -No external dependencies. -No ORM. -No dependency injection. -No magic. +If a feature can be implemented with a few lines of plain PHP, prefer that approach. -Just PHP. +miniPHP exists for developers who want: + +* A clean starting point +* Full control over their code +* Zero framework lock-in +* Zero external dependencies --- @@ -25,20 +33,54 @@ Just PHP. * No Composer required * Simple config-based router * Page and API endpoints +* Route prefix support * SQLite support via PDO -* Shared partials -* Secure path traversal protection +* Shared view partials * Helper functions +* Path traversal protection * Development server script +* Project initialization script + +--- + +## Quick Start + +Clone the repository: + +```bash +git clone my-project +cd my-project +``` + +Initialize the project: + +```bash +./init_miniphp.sh +``` + +The initializer will: + +* Remove the template git remote +* Generate a new README +* Prepare the project for a new repository + +Then create your own repository and connect it: + +```bash +git remote add origin +git push -u origin main +``` + +Start building. --- ## Requirements * PHP 8.1+ -* SQLite extension (optional) +* PDO SQLite extension (optional) -Check installed extensions: +View installed extensions: ```bash php -m @@ -57,7 +99,7 @@ public/ ├── css/ │ └── app.css └── js/ - └── app.js +│ └── app.js src/ ├── api/ @@ -74,6 +116,7 @@ storage/ index.php server.sh +init_miniphp.sh ``` --- @@ -94,7 +137,7 @@ http://127.0.0.1:3333 --- -## Routes +## Routing Routes are defined in: @@ -107,26 +150,22 @@ Example: ```php return [ 'GET' => [ - '/' => 'home.php', - '/about' => 'about.php', - '/api/test' => 'api/example.php', + '/' => 'home.php', + '/about' => 'about.php', + '/api/test' => 'api/example.php', ], ]; ``` -## Route Prefixes +### Route Prefixes -Routes can be mapped to different source directories using prefixes. - -By default: +By default page routes resolve to: ```text src/views/pages/ ``` -is used for normal pages. - -The router also supports configurable route prefixes: +Additional route prefixes can be registered: ```php $route_bases = [ @@ -158,7 +197,7 @@ loads: src/views/pages/about.php ``` -### Adding A New Route Type +### Creating New Route Types Create a new directory: @@ -166,7 +205,7 @@ Create a new directory: src/docs/ ``` -Then add a prefix: +Register it: ```php $route_bases = [ @@ -181,19 +220,17 @@ Now: '/docs/getting-started' => 'docs/getting-started.php', ``` -will load: +resolves to: ```text src/docs/getting-started.php ``` -No router changes required. +No router modifications required. --- -## Adding A New Page - -### 1. Create the page +## Pages Create: @@ -210,20 +247,10 @@ Example:

Get in touch.

- ``` -### 2. Add the route - -Edit: - -```php -config/routes.php -``` - -Add: +Register the route: ```php 'GET' => [ @@ -239,9 +266,7 @@ http://localhost:3333/contact --- -## Adding An API Endpoint - -### 1. Create the endpoint +## API Endpoints Create: @@ -258,10 +283,10 @@ declare(strict_types=1); header('Content-Type: application/json'); -echo json_encode(['success' => true]); +echo json_encode([ 'success' => true, ]); ``` -### 2. Add the route +Register the route: ```php 'GET' => [ @@ -269,17 +294,11 @@ echo json_encode(['success' => true]); ], ``` -Visit: - -```text -http://localhost:8000/api/contact -``` - --- -## SQLite +## Database -Database configuration: +Configuration: ```php config/database.php @@ -290,14 +309,14 @@ Usage: ```php $db = db(); -$rows = $db->query('SELECT * FROM users')->fetchAll(); +$rows = $db->query( 'SELECT * FROM users')->fetchAll(); ``` --- ## Helpers -Available helpers: +Included helpers: ```php escape_string() @@ -309,16 +328,7 @@ partial() --- -## Philosophy - -miniPHP intentionally avoids framework features. - -If a feature can be implemented with plain PHP and a few lines of code, prefer that approach. - -The goal is to remain small, understandable, and easy to clone for future projects. - ---- - ## License MIT + diff --git a/init_miniphp.sh b/init_miniphp.sh new file mode 100755 index 0000000..137554b --- /dev/null +++ b/init_miniphp.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -e + +echo "=================================" +echo " MiniPHP Initializer" +echo "=================================" +echo + +# Remove git remote if it exists +if git remote get-url origin >/dev/null 2>&1; then + git remote remove origin + echo "[✓] Removed existing git remote 'origin'" +else + echo "[i] No git remote 'origin' found" +fi + +echo + +# Gather README information +read -rp "Project title: " PROJECT_TITLE +read -rp "Project description: " PROJECT_DESCRIPTION + +# Create README +cat > README.md << EOF +# ${PROJECT_TITLE} + +${PROJECT_DESCRIPTION} +EOF + +echo "[✓] Generated README.md" +echo +echo "=================================" +echo " Next Steps" +echo "=================================" +echo +echo "Create a new repository and add it as the remote:" +echo +echo " git remote add origin " +echo " git branch -M main" +echo " git push -u origin main" +echo + +# Optional self-delete +read -rp "Delete init_miniphp.sh? [y/N]: " DELETE_SCRIPT +case "$DELETE_SCRIPT" in + [yY]|[yY][eE][sS]) + SCRIPT_PATH="$(realpath "$0")" + echo "[✓] Removing $SCRIPT_PATH" + rm -f "$SCRIPT_PATH" + ;; + *) + echo "[i] Keeping init_miniphp.sh" + ;; +esac + +echo +echo "[✓] Initialization complete"