|
1 | | -# WEBT_25-26_04-CORE |
| 1 | +# WEBT_25-26_03-ADV |
2 | 2 |
|
3 | | -WEBT-VT | CORE | 04 - Composer and Views in MVC |
| 3 | +WEBT-VT | ADV | 03 - Coding Standards |
4 | 4 |
|
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 |
73 | 6 |
|
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** |
75 | 10 |
|
76 | | ---- |
| 11 | +- **Server:** Docker |
| 12 | +- **Configuration file:** `./WEBT_25-26_03-ADV/docker-compose.yaml` |
| 13 | +- **Service:** `web` |
| 14 | +- **PHP executable:** `php` |
77 | 15 |
|
78 | | -### User Stories 5 & 6: Templating Engine & Dynamic Rendering |
| 16 | +* **Lifecycle:** Connect to existing container ('docker-compose exec') |
| 17 | +* **CLI Interpreter:** `web` |
79 | 18 |
|
80 | | -**Relevant files:** |
| 19 | +### PHP CS Fixer in PhpStorm konfigurieren |
81 | 20 |
|
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` |
85 | 26 |
|
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 |
88 | 28 |
|
89 | | ---- |
| 29 | +`Ctrl + Shift + A -> "Fix CS"` |
90 | 30 |
|
91 | | -### User Story 7: QR Code Generation & Integration |
| 31 | +### Reformat at File save |
92 | 32 |
|
93 | | -**Relevant files:** |
| 33 | +* File -> Settings -> PHP -> Quality Tools -> **External Formatters:** `PHP CS Fixer` |
| 34 | +* `Settings -> Tools -> Action on Save` |
94 | 35 |
|
95 | | -* `src/QrCode/QrCodeBuilder.php` |
96 | | -* `public/index.php` |
97 | | -* `public/api.php` |
| 36 | +- Select `Reformat code` & `Rearrange code` |
98 | 37 |
|
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 |
100 | 39 |
|
101 | | ---- |
| 40 | +#### Standard |
102 | 41 |
|
103 | | -### User Story 8: Interactive QR Code Generator |
| 42 | +* PSR-12 |
104 | 43 |
|
105 | | -**Relevant files:** |
| 44 | +#### Tooling |
106 | 45 |
|
107 | | -* `public/form.php` |
108 | | -* `templates/form.html` |
| 46 | +* PHP CS Fixer |
| 47 | +* Configuration: .php-cs-fixer.php |
109 | 48 |
|
110 | | -Users can enter a meal ID and generate a QR code dynamically via a styled form. |
| 49 | +#### Rules |
111 | 50 |
|
112 | | ---- |
| 51 | +* 4-space indentation |
| 52 | +* One class per file |
| 53 | +* Strict type declarations |
113 | 54 |
|
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 |
150 | 56 |
|
151 | | -* Generates demo meal plan data |
152 | | -* Simulates database content |
153 | | -* Used for dynamic rendering |
| 57 | +`composer require --dev friendsofphp/php-cs-fixer` |
154 | 58 |
|
155 | | ---- |
156 | | - |
157 | | -## Setup & Run the Project |
| 59 | +### Using PHP CS Fixer via the command line |
158 | 60 |
|
159 | 61 | ```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 |
166 | 65 | ``` |
167 | 66 |
|
168 | | -Open in your browser: |
169 | | - |
170 | | -* http://localhost:8080 |
171 | | -* http://localhost:8080/form.php |
| 67 | +## Setup & Run the Project |
172 | 68 |
|
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 | +``` |
0 commit comments