- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Router\ValueObjects\RoutePath;
|
|
use App\Framework\Router\ValueObjects\TypedPlaceholder;
|
|
use App\Framework\TypeCaster\TypeCasterRegistry;
|
|
use App\Framework\TypeCaster\Casters\EmailCaster;
|
|
use App\Framework\TypeCaster\Casters\UuidCaster;
|
|
use App\Framework\TypeCaster\Casters\HashCaster;
|
|
use App\Framework\DI\DefaultContainer;
|
|
use App\Domain\ValueObjects\EmailAddress;
|
|
use App\Framework\Core\ValueObjects\Hash;
|
|
|
|
echo "=== Testing Typed Route Parameters with TypeCasters ===\n\n";
|
|
|
|
// Setup TypeCaster Registry
|
|
$container = new DefaultContainer();
|
|
$registry = new TypeCasterRegistry($container);
|
|
|
|
// Register some casters
|
|
$emailCaster = new EmailCaster();
|
|
$registry->register(EmailCaster::class, $emailCaster);
|
|
|
|
$hashCaster = new HashCaster();
|
|
$registry->register(HashCaster::class, $hashCaster);
|
|
|
|
echo "1. Creating TypedPlaceholder for EmailAddress:\n";
|
|
try {
|
|
$emailPlaceholder = TypedPlaceholder::for(
|
|
EmailAddress::class,
|
|
$registry,
|
|
'userEmail'
|
|
);
|
|
|
|
echo " ✅ Created typed placeholder: {$emailPlaceholder->toString()}\n";
|
|
echo " 📧 Pattern: {$emailPlaceholder->getPattern()}\n";
|
|
|
|
// Test conversion
|
|
$testEmail = 'user@example.com';
|
|
$convertedEmail = $emailPlaceholder->convertValue($testEmail);
|
|
echo " 🔄 Converted '{$testEmail}' to: " . get_class($convertedEmail) . "\n";
|
|
echo " 📋 Value: {$convertedEmail->value}\n\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "2. Creating TypedPlaceholder for Hash:\n";
|
|
try {
|
|
$hashPlaceholder = TypedPlaceholder::for(
|
|
Hash::class,
|
|
$registry,
|
|
'fileHash'
|
|
);
|
|
|
|
echo " ✅ Created typed placeholder: {$hashPlaceholder->toString()}\n";
|
|
echo " 🔐 Pattern: {$hashPlaceholder->getPattern()}\n";
|
|
|
|
// Test conversion with proper SHA256 hash (64 characters)
|
|
$testHash = 'a1b2c3d4e5f67890123456789012345678901234567890123456789012345678';
|
|
$convertedHash = $hashPlaceholder->convertValue($testHash);
|
|
echo " 🔄 Converted hash to: " . get_class($convertedHash) . "\n";
|
|
echo " 📋 Value: {$convertedHash->toString()}\n\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "3. Creating RoutePath with TypedPlaceholders:\n";
|
|
try {
|
|
$routePath = RoutePath::fromElements(
|
|
'api',
|
|
'users',
|
|
TypedPlaceholder::for(EmailAddress::class, $registry, 'email'),
|
|
'files',
|
|
TypedPlaceholder::for(Hash::class, $registry, 'hash')
|
|
);
|
|
|
|
echo " ✅ Created route: {$routePath->toString()}\n";
|
|
echo " 🎯 Is dynamic: " . ($routePath->isDynamic() ? 'Yes' : 'No') . "\n";
|
|
echo " 📝 Parameters: " . implode(', ', $routePath->getParameterNames()) . "\n\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "4. Testing unsupported type (should fail gracefully):\n";
|
|
try {
|
|
$unsupportedPlaceholder = TypedPlaceholder::for(
|
|
'NonExistentClass',
|
|
$registry
|
|
);
|
|
echo " ❌ This should not succeed!\n";
|
|
} catch (\Throwable $e) {
|
|
echo " ✅ Expected error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "=== Typed Route Parameters Test Completed ===\n"; |