Files
michaelschiemer/tests/debug/test-foreach-processing.php
Michael Schiemer c8b47e647d feat(Docker): Upgrade to PHP 8.5.0RC3 with native ext-uri support
BREAKING CHANGE: Requires PHP 8.5.0RC3

Changes:
- Update Docker base image from php:8.4-fpm to php:8.5.0RC3-fpm
- Enable ext-uri for native WHATWG URL parsing support
- Update composer.json PHP requirement from ^8.4 to ^8.5
- Add ext-uri as required extension in composer.json
- Move URL classes from Url.php85/ to Url/ directory (now compatible)
- Remove temporary PHP 8.4 compatibility workarounds

Benefits:
- Native URL parsing with Uri\WhatWg\Url class
- Better performance for URL operations
- Future-proof with latest PHP features
- Eliminates PHP version compatibility issues
2025-10-27 09:31:28 +01:00

82 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\DI\DefaultContainer;
use App\Framework\View\DomWrapper;
use App\Framework\View\Processors\ForProcessor;
use App\Framework\View\RenderContext;
use App\Framework\Meta\MetaData;
// Initialize container
$container = new DefaultContainer();
// Create ForProcessor
$forProcessor = $container->get(ForProcessor::class);
// Test HTML with foreach attribute
$html = <<<'HTML'
<!DOCTYPE html>
<html>
<body>
<table>
<thead>
<tr>
<th>Model</th>
<th>Version</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr foreach="$models as $model">
<td>{{ $model['model_name'] }}</td>
<td>{{ $model['version'] }}</td>
<td>{{ $model['status'] }}</td>
</tr>
</tbody>
</table>
</body>
</html>
HTML;
// Test data
$data = [
'models' => [
['model_name' => 'fraud-detector', 'version' => '1.0.0', 'status' => 'healthy'],
['model_name' => 'spam-classifier', 'version' => '2.0.0', 'status' => 'degraded'],
]
];
// Create render context
$context = new RenderContext(
template: 'test',
metaData: new MetaData('test', 'test'),
data: $data,
controllerClass: null
);
// Process
echo "=== ORIGINAL HTML ===\n";
echo $html . "\n\n";
$dom = DomWrapper::fromString($html);
echo "=== CHECKING FOR FOREACH NODES ===\n";
$foreachNodes = $dom->document->querySelectorAll('[foreach]');
echo "Found " . count($foreachNodes) . " foreach nodes\n\n";
foreach ($foreachNodes as $idx => $node) {
echo "Node $idx:\n";
echo " Tag: " . $node->tagName . "\n";
echo " Foreach: " . $node->getAttribute('foreach') . "\n";
echo " HTML: " . substr($dom->document->saveHTML($node), 0, 200) . "\n\n";
}
echo "=== PROCESSING WITH ForProcessor ===\n";
$processedDom = $forProcessor->process($dom, $context);
echo "=== PROCESSED HTML ===\n";
echo $processedDom->toHtml(true) . "\n";