|
| 1 | +# PHP Interactive Scenario Generation |
| 2 | + |
| 3 | +## MANDATORY: Knowledge Base Consultation (FIRST STEP) |
| 4 | +**🚨 CRITICAL - Must be completed BEFORE any code generation** |
| 5 | + |
| 6 | +```bash |
| 7 | +# Step 1: List available knowledge bases |
| 8 | +ListKnowledgeBases() |
| 9 | + |
| 10 | +# Step 2: Query coding standards (REQUIRED) |
| 11 | +QueryKnowledgeBases("coding-standards-KB", "PHP-code-example-standards") |
| 12 | + |
| 13 | +# Step 3: Query implementation patterns (REQUIRED) |
| 14 | +QueryKnowledgeBases("PHP-premium-KB", "PHP implementation patterns structure") |
| 15 | + |
| 16 | +# Step 4: AWS service research (REQUIRED) |
| 17 | +search_documentation("What is [AWS Service] and what are its key API operations?") |
| 18 | +read_documentation("https://docs.aws.amazon.com/[service]/latest/[relevant-page]") |
| 19 | +``` |
| 20 | + |
| 21 | +**FAILURE TO COMPLETE KNOWLEDGE BASE CONSULTATION WILL RESULT IN INCORRECT CODE STRUCTURE** |
| 22 | + |
| 23 | +## Purpose |
| 24 | +Generate interactive scenarios that demonstrate complete workflows using multiple service operations in a guided, educational manner. Implementation must be based on the service SPECIFICATION.md file. |
| 25 | + |
| 26 | +## Requirements |
| 27 | +- **Specification-Driven**: MUST read the `scenarios/basics/{service}/SPECIFICATION.md` |
| 28 | +- **Interactive**: Use `testable_readline()` for user input and clear output |
| 29 | +- **Educational**: Break complex workflows into logical phases |
| 30 | +- **Comprehensive**: Cover setup, demonstration, examination, and cleanup |
| 31 | +- **Error Handling**: Graceful error handling with user-friendly messages |
| 32 | +- **Service Classes**: MUST use service wrapper classes for all operations |
| 33 | +- **Runner Pattern**: MUST implement interactive Runner.php pattern |
| 34 | + |
| 35 | +## File Structure |
| 36 | +``` |
| 37 | +example_code/{service}/ |
| 38 | +├── Runner.php # Interactive menu runner |
| 39 | +├── {Service}Service.php # Service wrapper class |
| 40 | +├── composer.json |
| 41 | +├── README.md |
| 42 | +└── tests/ |
| 43 | + ├── {Service}Test.php |
| 44 | + └── phpunit.xml |
| 45 | +```## MA |
| 46 | +NDATORY Pre-Implementation Steps |
| 47 | +
|
| 48 | +### Step 1: Read Service Specification |
| 49 | +**CRITICAL**: Always read `scenarios/basics/{service}/SPECIFICATION.md` first to understand: |
| 50 | +- **API Actions Used**: Exact operations to implement |
| 51 | +- **Proposed Example Structure**: Setup, demonstration, examination, cleanup phases |
| 52 | +- **Error Handling**: Specific error codes and handling requirements |
| 53 | +- **Scenario Flow**: Step-by-step workflow description |
| 54 | +
|
| 55 | +### Step 2: Extract Implementation Requirements |
| 56 | +From the specification, identify: |
| 57 | +- **Setup Phase**: What resources need to be created/configured |
| 58 | +- **Demonstration Phase**: What operations to demonstrate |
| 59 | +- **Examination Phase**: What data to display and how to filter/analyze |
| 60 | +- **Cleanup Phase**: What resources to clean up and user options |
| 61 | +
|
| 62 | +## Runner Pattern Structure |
| 63 | +**MANDATORY for most services:** |
| 64 | +
|
| 65 | +```php |
| 66 | +<?php |
| 67 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 68 | +// SPDX-License-Identifier: Apache-2.0 |
| 69 | +
|
| 70 | +require 'vendor/autoload.php'; |
| 71 | +
|
| 72 | +use {Service}\{Service}Service; |
| 73 | +
|
| 74 | +echo "Welcome to the {AWS Service} examples!\n"; |
| 75 | +echo "Choose an option:\n"; |
| 76 | +echo "1. Hello {Service}\n"; |
| 77 | +echo "2. Run {Service} Basics Scenario\n"; |
| 78 | +echo "3. List {Resources}\n"; |
| 79 | +echo "4. Create {Resource}\n"; |
| 80 | +echo "5. Delete {Resource}\n"; |
| 81 | +echo "0. Exit\n"; |
| 82 | +
|
| 83 | +$choice = testable_readline("Enter your choice: "); |
| 84 | +
|
| 85 | +switch ($choice) { |
| 86 | + case '1': |
| 87 | + require 'Hello{Service}.php'; |
| 88 | + break; |
| 89 | + case '2': |
| 90 | + $service = new {Service}Service(); |
| 91 | + runBasicsScenario($service); |
| 92 | + break; |
| 93 | + case '3': |
| 94 | + $service = new {Service}Service(); |
| 95 | + $service->list{Resources}(); |
| 96 | + break; |
| 97 | + case '4': |
| 98 | + $service = new {Service}Service(); |
| 99 | + $resourceName = testable_readline("Enter resource name: "); |
| 100 | + $service->create{Resource}($resourceName); |
| 101 | + break; |
| 102 | + case '5': |
| 103 | + $service = new {Service}Service(); |
| 104 | + $resourceId = testable_readline("Enter resource ID: "); |
| 105 | + $service->delete{Resource}($resourceId); |
| 106 | + break; |
| 107 | + case '0': |
| 108 | + echo "Goodbye!\n"; |
| 109 | + break; |
| 110 | + default: |
| 111 | + echo "Invalid choice\n"; |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +## Scenario Phase Structure (Based on Specification) |
| 116 | + |
| 117 | +### Setup Phase |
| 118 | +- **Read specification Setup section** for exact requirements |
| 119 | +- Check for existing resources as specified |
| 120 | +- Create necessary resources using service methods |
| 121 | +- Configure service settings per specification |
| 122 | +- Verify setup completion as described |
| 123 | + |
| 124 | +### Demonstration Phase |
| 125 | +- **Follow specification Demonstration section** exactly |
| 126 | +- Perform core service operations using service methods |
| 127 | +- Generate sample data if specified in the specification |
| 128 | +- Show service capabilities as outlined |
| 129 | +- Provide educational context from specification |
| 130 | + |
| 131 | +### Examination Phase |
| 132 | +- **Implement specification Examination section** requirements |
| 133 | +- List and examine results using service methods |
| 134 | +- Filter and analyze data as specified |
| 135 | +- Display detailed information per specification format |
| 136 | +- Allow user interaction as described in specification |
| 137 | + |
| 138 | +### Cleanup Phase |
| 139 | +- **Follow specification Cleanup section** guidance |
| 140 | +- Offer cleanup options with warnings from specification |
| 141 | +- Handle cleanup errors gracefully using service methods |
| 142 | +- Provide alternative management options as specified |
| 143 | +- Confirm completion per specification |
| 144 | + |
| 145 | +## User Interaction Patterns |
| 146 | + |
| 147 | +### Input Handling |
| 148 | +```php |
| 149 | +// Yes/No questions |
| 150 | +$useExisting = testable_readline("Use existing resource? (y/n): "); |
| 151 | +$isYes = strtolower($useExisting) === 'y'; |
| 152 | + |
| 153 | +// Text input |
| 154 | +$resourceName = testable_readline("Enter resource name: "); |
| 155 | + |
| 156 | +// Numeric input with validation |
| 157 | +do { |
| 158 | + $count = testable_readline("How many items? "); |
| 159 | +} while (!is_numeric($count) || $count < 1); |
| 160 | +``` |
| 161 | + |
| 162 | +### Information Display |
| 163 | +```php |
| 164 | +// Progress indicators |
| 165 | +echo "✓ Operation completed successfully\n"; |
| 166 | +echo "⚠ Warning message\n"; |
| 167 | +echo "✗ Error occurred\n"; |
| 168 | + |
| 169 | +// Formatted output |
| 170 | +echo str_repeat('-', 60) . "\n"; |
| 171 | +echo "Found " . count($items) . " items:\n"; |
| 172 | +foreach ($items as $item) { |
| 173 | + echo " • {$item['name']}\n"; |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +## Runner Requirements |
| 178 | +- ✅ **ALWAYS** read and implement based on `scenarios/basics/{service}/SPECIFICATION.md` |
| 179 | +- ✅ **ALWAYS** provide interactive menu for multiple examples |
| 180 | +- ✅ **ALWAYS** include hello scenario as first option |
| 181 | +- ✅ **ALWAYS** handle user input gracefully using `testable_readline()` |
| 182 | +- ✅ **ALWAYS** include proper error handling |
| 183 | +- ✅ **ALWAYS** provide clear output and feedback |
| 184 | +- ✅ **ALWAYS** use service wrapper classes for all AWS operations |
| 185 | +- ✅ **ALWAYS** implement proper cleanup in finally block |
| 186 | +- ✅ **ALWAYS** break scenario into logical phases per specification |
| 187 | +- ✅ **ALWAYS** include error handling per specification's Errors section |
| 188 | +- ✅ **ALWAYS** provide educational context and explanations from specification |
0 commit comments