Skip to content

Commit 42425f7

Browse files
authored
Merge branch 'main' into main
2 parents 8b28779 + 06b2d70 commit 42425f7

18 files changed

+2781
-172
lines changed

.github/workflows/php-cs-fixer.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PHP Code Style
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
php-cs-fixer:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: 8.2
19+
20+
- name: Install dependencies
21+
run: composer install --no-interaction --no-progress
22+
23+
- name: Run PHP CS Fixer
24+
run: vendor/bin/php-cs-fixer fix --dry-run --diff

.php-cs-fixer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
return (new PhpCsFixer\Config())
4+
->setRules([
5+
'@PSR12' => true,
6+
])
7+
->setFinder(
8+
PhpCsFixer\Finder::create()
9+
->in(__DIR__)
10+
);

15_digital_meal_plan.pdf

-28.5 KB
Binary file not shown.

README.md

Lines changed: 48 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,75 @@
1-
# WEBT_25-26_04-CORE
1+
# WEBT_25-26_03-ADV
22

3-
WEBT-VT | CORE | 04 - Composer and Views in MVC
3+
WEBT-VT | ADV | 03 - Coding Standards
44

5-
## Composer Infos
6-
7-
* ```composer require {package}``` to install
8-
* https://packagist.org to search for composer packages
9-
* ```composer dump-autoload``` to reload Autoloading
10-
11-
## Digital Meal Plan – Project Overview
12-
13-
This project is a sample web application for a **Digital Meal Plan** and was developed as part of the exercise **WEBT
14-
Core – Composer & MVC Templating**.
15-
16-
The goal of the project is to demonstrate:
17-
18-
* how to use Composer in a PHP project
19-
* how to implement a simple custom templating engine
20-
* how to render dynamic content using loops
21-
* how to generate and integrate QR codes using `endroid/qr-code`
22-
23-
---
24-
25-
## Project Structure (High-Level)
26-
27-
```
28-
├── composer.json # Composer configuration & dependencies
29-
├── composer.lock # Locked dependency versions
30-
├── public/
31-
│ ├── index.php # Main page: displays all meal plans
32-
│ ├── api.php # JSON API for single meal
33-
│ ├── form.php # Interactive QR code generator form
34-
│ ├── qrCodeExample.php # Simple QR code demo script
35-
│ └── styles/
36-
│ └── style.css # Global styling for the project
37-
├── src/
38-
│ ├── Api/
39-
│ │ └── GetMeals.php # Returns a meal as JSON
40-
│ ├── QrCode/
41-
│ │ └── QrCodeBuilder.php # Wrapper for endroid/qr-code
42-
│ ├── Seeder/
43-
│ │ └── MealSeeder.php # Generates example meal plans
44-
│ └── View/
45-
│ └── TemplateEngine.php # Custom templating engine
46-
├── templates/
47-
│ ├── index.html # Template for meal plan overview
48-
│ └── form.html # Template for QR code form
49-
└── vendor/ # Composer dependencies (auto-generated)
50-
```
51-
52-
---
53-
54-
### User Stories 1–3: Composer & QR Code Package
55-
56-
**Relevant files:**
57-
58-
* `composer.json`
59-
* `vendor/`
60-
* `public/qrCodeExample.php`
61-
62-
Composer is initialized, PSR-4 autoloading is configured, and the package `endroid/qr-code` is
63-
installed and used.
64-
65-
---
66-
67-
### User Story 4: Meal Plan HTML Prototype
68-
69-
**Relevant files:**
70-
71-
* `templates/index.html`
72-
* `public/styles/style.css`
5+
### PHP Interpreter aus Docker in PhpStorm einrichten
736

74-
Defines the responsive HTML structure and basic styling for displaying multiple meal plans.
7+
* File -> Settings -> PHP
8+
* Auf `...` neben **CLI Interpreter** klicken
9+
* `+` -> **From Docker** -> **Docker Composer**
7510

76-
---
11+
- **Server:** Docker
12+
- **Configuration file:** `./WEBT_25-26_03-ADV/docker-compose.yaml`
13+
- **Service:** `web`
14+
- **PHP executable:** `php`
7715

78-
### User Stories 5 & 6: Templating Engine & Dynamic Rendering
16+
* **Lifecycle:** Connect to existing container ('docker-compose exec')
17+
* **CLI Interpreter:** `web`
7918

80-
**Relevant files:**
19+
### PHP CS Fixer in PhpStorm konfigurieren
8120

82-
* `src/View/TemplateEngine.php`
83-
* `public/index.php`
84-
* `templates/index.html`
21+
* File -> Settings -> PHP -> Quality Tools -> PHP CS Fixer
22+
* Auf `...` neben **Configuration** klicken
23+
* `+` -> **Interpreter:** `web`
24+
* **PHP CS Fixer path:** `./vendor/bin/php-cs-fixer`
25+
* **Path mappings:** Map ADV3 Folder to `/var/www/html`
8526

86-
The custom `TemplateEngine` replaces placeholders and supports loop constructs to dynamically render any number of meal
87-
plans and meals.
27+
### Reformat specific File with PhpStorm
8828

89-
---
29+
`Ctrl + Shift + A -> "Fix CS"`
9030

91-
### User Story 7: QR Code Generation & Integration
31+
### Reformat at File save
9232

93-
**Relevant files:**
33+
* File -> Settings -> PHP -> Quality Tools -> **External Formatters:** `PHP CS Fixer`
34+
* `Settings -> Tools -> Action on Save`
9435

95-
* `src/QrCode/QrCodeBuilder.php`
96-
* `public/index.php`
97-
* `public/api.php`
36+
- Select `Reformat code` & `Rearrange code`
9837

99-
QR codes are generated for each meal plan and link to a JSON API endpoint that returns the meal data.
38+
### PHP Coding Standards
10039

101-
---
40+
#### Standard
10241

103-
### User Story 8: Interactive QR Code Generator
42+
* PSR-12
10443

105-
**Relevant files:**
44+
#### Tooling
10645

107-
* `public/form.php`
108-
* `templates/form.html`
46+
* PHP CS Fixer
47+
* Configuration: .php-cs-fixer.php
10948

110-
Users can enter a meal ID and generate a QR code dynamically via a styled form.
49+
#### Rules
11150

112-
---
51+
* 4-space indentation
52+
* One class per file
53+
* Strict type declarations
11354

114-
## File Descriptions
115-
116-
### `public/index.php`
117-
118-
* Main entry point of the application
119-
* Loads demo data using `MealSeeder`
120-
* Generates QR codes for each meal plan
121-
* Passes structured data to the template engine
122-
123-
### `public/api.php`
124-
125-
* Simple JSON API endpoint
126-
* Returns a single meal plan by ID
127-
* Used as the target URL for QR codes
128-
129-
### `public/form.php`
130-
131-
* Handles POST requests
132-
* Validates user input (meal ID)
133-
* Generates QR codes dynamically
134-
* Renders output via `form.html`
135-
136-
### `src/View/TemplateEngine.php`
137-
138-
* Custom mini templating engine
139-
* Replaces placeholders in HTML templates
140-
* Supports loops and nested loops
141-
* Ensures separation of logic and presentation
142-
143-
### `src/QrCode/QrCodeBuilder.php`
144-
145-
* Encapsulates QR code generation logic
146-
* Wraps the `endroid/qr-code` library
147-
* Provides a clean and reusable interface
148-
149-
### `src/Seeder/MealSeeder.php`
55+
## Composer Infos
15056

151-
* Generates demo meal plan data
152-
* Simulates database content
153-
* Used for dynamic rendering
57+
`composer require --dev friendsofphp/php-cs-fixer`
15458

155-
---
156-
157-
## Setup & Run the Project
59+
### Using PHP CS Fixer via the command line
15860

15961
```bash
160-
161-
docker compose up -d
162-
docker exec -it CORE4 bash
163-
164-
git config --global --add safe.directory /var/www/html
165-
composer install
62+
docker exec -it ADV3 bash
63+
vendor/bin/php-cs-fixer fix
64+
exit
16665
```
16766

168-
Open in your browser:
169-
170-
* http://localhost:8080
171-
* http://localhost:8080/form.php
67+
## Setup & Run the Project
17268

173-
---
69+
```bash
70+
docker compose up -d
71+
docker exec -it ADV3 bash
72+
73+
git config --global --add safe.directory /var/www/html
74+
composer install
75+
```

composer.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
2-
"name": "radlinger/mealplan",
3-
"description": "Project for our WEBT Core 4 exercise with the topic MealPlan",
4-
"autoload": {
5-
"psr-4": {
6-
"Radlinger\\Mealplan\\": "src/"
7-
}
8-
},
9-
"require": {
10-
"endroid/qr-code": "^6.0"
2+
"name": "radlinger/mealplan",
3+
"description": "Project for our WEBT ADV 3 exercise with the topic MealPlan",
4+
"autoload": {
5+
"psr-4": {
6+
"Radlinger\\Mealplan\\": "src/"
117
}
8+
},
9+
"require": {
10+
"php": "^8.2",
11+
"endroid/qr-code": "^6.0"
12+
},
13+
"require-dev": {
14+
"friendsofphp/php-cs-fixer": "^3.92"
15+
}
1216
}

0 commit comments

Comments
 (0)