💻 Practical Exam: Composer & PHP Packages
⏱ Duration: 2–3 Hours
🎯 Objective: Test real-world Composer usage
🟢 Section A: Setup (Basic – 10 Marks)
✅ Task 1:
- Create a new project folder:
composer-exam - Initialize Composer:
composer init
✅ Task 2:
- Install these packages:
composer require monolog/monolog
composer require guzzlehttp/guzzle
composer require phpmailer/phpmailer
👉 Evaluation:
- composer.json created ✔
- vendor/ folder exists ✔
🟡 Section B: Logging System (20 Marks)
✅ Task:
Create a file: logger.php
👉 Requirements:
- Use Monolog
- Log messages into
logs/app.log - Add:
- INFO → “User visited site”
- WARNING → “Invalid login attempt”
- ERROR → “System failure”
👉 Expected Skills:
- Autoload usage
- Package integration
🟡 Section C: API Integration (20 Marks)
✅ Task:
Create api.php
👉 Requirements:
- Use Guzzle
- Fetch data from:
https://jsonplaceholder.typicode.com/users
👉 Output:
- Display:
- Name
- Show only first 3 users
👉 Bonus:
- Handle API error (try-catch)
🟠 Section D: Email System (20 Marks)
✅ Task:
Create mail.php
👉 Requirements:
- Use PHPMailer
- Send test email
Fields:
- From: your_email@example.com
- To: test@example.com
- Subject: Test Mail
- Body: Hello from Composer
👉 Bonus:
- Use SMTP configuration
🔴 Section E: Autoloading (15 Marks)
✅ Task:
Implement PSR-4 Autoloading
👉 Step 1: Update composer.json
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
👉 Step 2:
composer dump-autoload
👉 Step 3:
Create:
📁 src/User.php
namespace App;class User {
public function getName() {
return "Aditya";
}
}
👉 Step 4:
Use it in index.php
🔴 Section F: Mini Project (15 Marks)
✅ Build: Simple Contact Form System
👉 Requirements:
- HTML form:
- Name
- Message
- On submit:
- Log request (Monolog)
- Send email (PHPMailer)
👉 Bonus:
- Validate inputs
🧠 Section G: Debugging (Bonus – 10 Marks)
Scenario:
- Delete
vendor/folder
👉 Task:
- Restore project using Composer
✔ Expected command:
composer install
📊 Marking Scheme
| Section | Marks |
|---|---|
| Setup | 10 |
| Logging | 20 |
| API | 20 |
| 20 | |
| Autoloading | 15 |
| Mini Project | 15 |
| Bonus | 10 |
🎯 Evaluation Criteria
- ✔ Proper Composer usage
- ✔ Clean code
- ✔ Error handling
- ✔ File structure
- ✔ Real-world logic
📁 Expected Folder Structure
composer-exam/
│
├── composer.json
├── vendor/
├── index.php
├── logger.php
├── api.php
├── mail.php
├── src/
│ └── User.php
├── logs/
│ └── app.log
🚀 Pro-Level Challenge (Optional)
👉 Add:
.envfile for config- Use
vlucas/phpdotenv






