- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
110 lines
3.5 KiB
PHP
110 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\LiveComponents\Rendering;
|
|
|
|
use App\Framework\LiveComponents\Contracts\LiveComponentContract;
|
|
use App\Framework\LiveComponents\ValueObjects\FragmentCollection;
|
|
use App\Framework\View\LiveComponentRenderer;
|
|
|
|
/**
|
|
* Fragment Renderer
|
|
*
|
|
* Handles partial rendering of LiveComponents by extracting specific
|
|
* fragments from the full component HTML.
|
|
*
|
|
* Workflow:
|
|
* 1. Render full component HTML using LiveComponentRenderer
|
|
* 2. Extract requested fragments using FragmentExtractor
|
|
* 3. Return FragmentCollection with extracted fragments
|
|
* 4. Fallback to full render if fragments not found
|
|
*
|
|
* Benefits:
|
|
* - Reduces bandwidth by sending only changed fragments
|
|
* - Improves perceived performance with targeted updates
|
|
* - Maintains full HTML structure for graceful degradation
|
|
*/
|
|
final readonly class FragmentRenderer
|
|
{
|
|
public function __construct(
|
|
private LiveComponentRenderer $componentRenderer,
|
|
private FragmentExtractor $fragmentExtractor
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Render specific fragments of a component
|
|
*
|
|
* If no fragments are specified or found, returns empty collection.
|
|
* Client should fallback to full re-render in that case.
|
|
*
|
|
* @param LiveComponentContract $component Component to render
|
|
* @param array<string> $fragmentNames Fragment names to extract (e.g., ['user-stats', 'recent-activity'])
|
|
* @return FragmentCollection Collection of extracted fragments
|
|
*/
|
|
public function renderFragments(
|
|
LiveComponentContract $component,
|
|
array $fragmentNames
|
|
): FragmentCollection {
|
|
if (empty($fragmentNames)) {
|
|
return FragmentCollection::empty();
|
|
}
|
|
|
|
// Render full component HTML
|
|
$renderData = $component->getRenderData();
|
|
|
|
$fullHtml = $this->componentRenderer->render(
|
|
templatePath: $renderData->templatePath,
|
|
data: $renderData->data,
|
|
componentId: $component->id->toString()
|
|
);
|
|
|
|
// Extract requested fragments
|
|
return $this->fragmentExtractor->extract($fullHtml, $fragmentNames);
|
|
}
|
|
|
|
/**
|
|
* Check if component has specific fragment
|
|
*
|
|
* Useful for validating fragment names before attempting to render.
|
|
*
|
|
* @param LiveComponentContract $component Component to check
|
|
* @param string $fragmentName Fragment name to look for
|
|
* @return bool True if fragment exists in component template
|
|
*/
|
|
public function hasFragment(LiveComponentContract $component, string $fragmentName): bool
|
|
{
|
|
$renderData = $component->getRenderData();
|
|
|
|
$fullHtml = $this->componentRenderer->render(
|
|
templatePath: $renderData->templatePath,
|
|
data: $renderData->data,
|
|
componentId: $component->id->toString()
|
|
);
|
|
|
|
return $this->fragmentExtractor->hasFragment($fullHtml, $fragmentName);
|
|
}
|
|
|
|
/**
|
|
* Get all available fragment names from component
|
|
*
|
|
* Useful for debugging and introspection.
|
|
*
|
|
* @param LiveComponentContract $component Component to analyze
|
|
* @return array<string> Available fragment names
|
|
*/
|
|
public function getAvailableFragments(LiveComponentContract $component): array
|
|
{
|
|
$renderData = $component->getRenderData();
|
|
|
|
$fullHtml = $this->componentRenderer->render(
|
|
templatePath: $renderData->templatePath,
|
|
data: $renderData->data,
|
|
componentId: $component->id->toString()
|
|
);
|
|
|
|
return $this->fragmentExtractor->getFragmentNames($fullHtml);
|
|
}
|
|
}
|