feat(Deployment): Integrate Ansible deployment via PHP deployment pipeline

- Create AnsibleDeployStage using framework's Process module for secure command execution
- Integrate AnsibleDeployStage into DeploymentPipelineCommands for production deployments
- Add force_deploy flag support in Ansible playbook to override stale locks
- Use PHP deployment module as orchestrator (php console.php deploy:production)
- Fix ErrorAggregationInitializer to use Environment class instead of $_ENV superglobal

Architecture:
- BuildStage → AnsibleDeployStage → HealthCheckStage for production
- Process module provides timeout, error handling, and output capture
- Ansible playbook supports rollback via rollback-git-based.yml
- Zero-downtime deployments with health checks
This commit is contained in:
2025-10-26 14:08:07 +01:00
parent a90263d3be
commit 3b623e7afb
170 changed files with 19888 additions and 575 deletions

View File

@@ -0,0 +1,283 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use App\Framework\Core\AppBootstrapper;
use App\Framework\Notification\Channels\TelegramChannel;
use App\Framework\Notification\Media\MediaManager;
use App\Framework\Notification\ValueObjects\NotificationChannel;
use App\Framework\Notification\Notification;
/**
* Rich Media Notification Example
*
* Demonstrates the MediaManager system for sending notifications with:
* - Photos
* - Videos
* - Audio files
* - Documents
* - Location data
*/
echo "🎨 Rich Media Notification System Example\n";
echo "==========================================\n\n";
// Bootstrap application
$app = AppBootstrapper::bootstrap();
$container = $app->getContainer();
// Get TelegramChannel with injected MediaManager
$telegramChannel = $container->get(TelegramChannel::class);
$mediaManager = $telegramChannel->mediaManager;
// Create sample notification
$notification = new Notification(
userId: 'user_123',
title: 'Rich Media Test',
body: 'Testing media capabilities',
channel: NotificationChannel::TELEGRAM,
type: 'media_test'
);
echo "📋 Testing MediaManager Capabilities\n";
echo "------------------------------------\n\n";
// 1. Check Telegram capabilities
echo "1⃣ Checking Telegram channel capabilities...\n";
$capabilities = $mediaManager->getCapabilities(NotificationChannel::TELEGRAM);
echo " Supported media types:\n";
echo " - Photos: " . ($capabilities->supportsPhoto ? '✅' : '❌') . "\n";
echo " - Videos: " . ($capabilities->supportsVideo ? '✅' : '❌') . "\n";
echo " - Audio: " . ($capabilities->supportsAudio ? '✅' : '❌') . "\n";
echo " - Documents: " . ($capabilities->supportsDocument ? '✅' : '❌') . "\n";
echo " - Location: " . ($capabilities->supportsLocation ? '✅' : '❌') . "\n";
echo " - Voice: " . ($capabilities->supportsVoice ? '✅' : '❌') . "\n\n";
// 2. Test photo support
echo "2⃣ Testing photo support...\n";
if ($mediaManager->supportsPhoto(NotificationChannel::TELEGRAM)) {
echo " ✅ Telegram supports photos\n";
// Example: Send photo with caption
try {
$photoNotification = new Notification(
userId: 'user_123',
title: 'Photo Notification',
body: 'Check out this image!',
channel: NotificationChannel::TELEGRAM,
type: 'photo_test'
);
// Note: In real usage, you would provide a valid file path or Telegram file_id
// $mediaManager->sendPhoto(
// NotificationChannel::TELEGRAM,
// $photoNotification,
// photoPath: '/path/to/image.jpg',
// caption: 'Beautiful landscape photo'
// );
echo " 📸 Photo sending method available\n";
} catch (\Exception $e) {
echo " ⚠️ Photo test skipped: {$e->getMessage()}\n";
}
} else {
echo " ❌ Telegram does not support photos\n";
}
echo "\n";
// 3. Test video support
echo "3⃣ Testing video support...\n";
if ($mediaManager->supportsVideo(NotificationChannel::TELEGRAM)) {
echo " ✅ Telegram supports videos\n";
// Example: Send video with thumbnail
try {
$videoNotification = new Notification(
userId: 'user_123',
title: 'Video Notification',
body: 'Watch this video!',
channel: NotificationChannel::TELEGRAM,
type: 'video_test'
);
// Note: In real usage, you would provide valid file paths
// $mediaManager->sendVideo(
// NotificationChannel::TELEGRAM,
// $videoNotification,
// videoPath: '/path/to/video.mp4',
// caption: 'Tutorial video',
// thumbnailPath: '/path/to/thumbnail.jpg'
// );
echo " 🎥 Video sending method available\n";
} catch (\Exception $e) {
echo " ⚠️ Video test skipped: {$e->getMessage()}\n";
}
} else {
echo " ❌ Telegram does not support videos\n";
}
echo "\n";
// 4. Test audio support
echo "4⃣ Testing audio support...\n";
if ($mediaManager->supportsAudio(NotificationChannel::TELEGRAM)) {
echo " ✅ Telegram supports audio\n";
// Example: Send audio file
try {
$audioNotification = new Notification(
userId: 'user_123',
title: 'Audio Notification',
body: 'Listen to this audio!',
channel: NotificationChannel::TELEGRAM,
type: 'audio_test'
);
// Note: In real usage, you would provide a valid audio file
// $mediaManager->sendAudio(
// NotificationChannel::TELEGRAM,
// $audioNotification,
// audioPath: '/path/to/audio.mp3',
// caption: 'Podcast episode',
// duration: 300 // 5 minutes
// );
echo " 🎵 Audio sending method available\n";
} catch (\Exception $e) {
echo " ⚠️ Audio test skipped: {$e->getMessage()}\n";
}
} else {
echo " ❌ Telegram does not support audio\n";
}
echo "\n";
// 5. Test document support
echo "5⃣ Testing document support...\n";
if ($mediaManager->supportsDocument(NotificationChannel::TELEGRAM)) {
echo " ✅ Telegram supports documents\n";
// Example: Send document
try {
$documentNotification = new Notification(
userId: 'user_123',
title: 'Document Notification',
body: 'Here is your document!',
channel: NotificationChannel::TELEGRAM,
type: 'document_test'
);
// Note: In real usage, you would provide a valid document
// $mediaManager->sendDocument(
// NotificationChannel::TELEGRAM,
// $documentNotification,
// documentPath: '/path/to/document.pdf',
// caption: 'Monthly report',
// filename: 'Report_2024.pdf'
// );
echo " 📄 Document sending method available\n";
} catch (\Exception $e) {
echo " ⚠️ Document test skipped: {$e->getMessage()}\n";
}
} else {
echo " ❌ Telegram does not support documents\n";
}
echo "\n";
// 6. Test location support
echo "6⃣ Testing location support...\n";
if ($mediaManager->supportsLocation(NotificationChannel::TELEGRAM)) {
echo " ✅ Telegram supports location sharing\n";
// Example: Send location
try {
$locationNotification = new Notification(
userId: 'user_123',
title: 'Location Notification',
body: 'Meet me here!',
channel: NotificationChannel::TELEGRAM,
type: 'location_test'
);
// Note: In real usage, you would provide actual coordinates
// $mediaManager->sendLocation(
// NotificationChannel::TELEGRAM,
// $locationNotification,
// latitude: 52.5200, // Berlin
// longitude: 13.4050,
// title: 'Meeting Point',
// address: 'Brandenburger Tor, Berlin'
// );
echo " 📍 Location sending method available\n";
} catch (\Exception $e) {
echo " ⚠️ Location test skipped: {$e->getMessage()}\n";
}
} else {
echo " ❌ Telegram does not support location sharing\n";
}
echo "\n";
// 7. Test error handling for unsupported channel
echo "7⃣ Testing error handling for unsupported channel...\n";
try {
// Try to check capabilities for a channel without registered driver
$emailCapabilities = $mediaManager->getCapabilities(NotificationChannel::EMAIL);
if (!$emailCapabilities->hasAnyMediaSupport()) {
echo " ✅ Email channel has no media support (as expected)\n";
}
} catch (\Exception $e) {
echo " ⚠️ Expected behavior: {$e->getMessage()}\n";
}
echo "\n";
// 8. Demonstrate runtime capability checking
echo "8⃣ Runtime capability checking pattern...\n";
$testChannel = NotificationChannel::TELEGRAM;
echo " Example: Sending media with runtime checks\n";
echo " \n";
echo " if (\$mediaManager->supportsPhoto(\$channel)) {\n";
echo " \$mediaManager->sendPhoto(\$channel, \$notification, \$photoPath);\n";
echo " } else {\n";
echo " // Fallback to text-only notification\n";
echo " \$channel->send(\$notification);\n";
echo " }\n";
echo "\n";
// Summary
echo "✅ Rich Media System Summary\n";
echo "============================\n\n";
echo "Architecture:\n";
echo "- MediaManager: Central management with driver registration\n";
echo "- MediaDriver: Marker interface with atomic capability interfaces\n";
echo "- Atomic Interfaces: SupportsPhotoAttachments, SupportsVideoAttachments, etc.\n";
echo "- TelegramMediaDriver: Full media support implementation\n\n";
echo "Key Features:\n";
echo "- ✅ Runtime capability detection via instanceof\n";
echo "- ✅ Type-safe media sending with validation\n";
echo "- ✅ Optional media support per channel\n";
echo "- ✅ Public MediaManager property on channels\n";
echo "- ✅ Graceful degradation for unsupported features\n\n";
echo "Usage:\n";
echo "1. Access MediaManager via channel: \$channel->mediaManager\n";
echo "2. Check capabilities before sending: \$mediaManager->supportsPhoto(\$channel)\n";
echo "3. Send media with validation: \$mediaManager->sendPhoto(...)\n";
echo "4. Handle unsupported media gracefully with fallbacks\n\n";
echo "✨ Example completed successfully!\n";