feat(Production): Complete production deployment infrastructure

- 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.
This commit is contained in:
2025-10-25 19:18:37 +02:00
parent caa85db796
commit fc3d7e6357
83016 changed files with 378904 additions and 20919 deletions

View File

@@ -0,0 +1,176 @@
<?php
declare(strict_types=1);
namespace App\Framework\LiveComponents\Rendering;
use App\Framework\LiveComponents\ValueObjects\ComponentFragment;
use App\Framework\LiveComponents\ValueObjects\FragmentCollection;
use App\Framework\Template\Parser\DomTemplateParser;
use App\Framework\View\DomWrapper;
use Dom\Element;
/**
* Fragment Extractor
*
* Extracts named fragments from rendered HTML using data-lc-fragment attributes.
* Uses Framework's DomTemplateParser and DomWrapper for robust HTML parsing.
*
* Supports:
* - Simple fragments: <div data-lc-fragment="name">...</div>
* - Nested fragments (inner fragments are included in outer fragment HTML)
*
* Performance:
* - Uses PHP 8.4's Dom\HTMLDocument for fast parsing
* - Leverages DomWrapper's getElementsByAttribute for efficient querying
*/
final readonly class FragmentExtractor
{
public function __construct(
private DomTemplateParser $parser
) {
}
/**
* Extract specific fragments from HTML
*
* @param string $html Full component HTML
* @param array<string> $fragmentNames Fragment names to extract
* @return FragmentCollection Extracted fragments
*/
public function extract(string $html, array $fragmentNames): FragmentCollection
{
if (empty($fragmentNames) || empty(trim($html))) {
return FragmentCollection::empty();
}
// Parse HTML using framework's parser
$wrapper = $this->parser->parseToWrapper($html);
// Extract requested fragments
$fragments = [];
foreach ($fragmentNames as $name) {
$fragmentHtml = $this->extractFragment($wrapper, $name);
if ($fragmentHtml !== null) {
$fragments[] = ComponentFragment::create($name, $fragmentHtml);
}
}
return FragmentCollection::fromFragments($fragments);
}
/**
* Extract all fragments from HTML
*
* @param string $html Full component HTML
* @return FragmentCollection All fragments found
*/
public function extractAll(string $html): FragmentCollection
{
if (empty(trim($html))) {
return FragmentCollection::empty();
}
// Parse HTML
$wrapper = $this->parser->parseToWrapper($html);
// Find all elements with data-lc-fragment attribute
$elementCollection = $wrapper->getElementsByAttribute('data-lc-fragment');
if ($elementCollection->isEmpty()) {
return FragmentCollection::empty();
}
$fragments = [];
foreach ($elementCollection->all() as $element) {
$name = $element->getAttribute('data-lc-fragment');
if (! empty($name)) {
$fragmentHtml = $this->elementToHtml($element);
$fragments[] = ComponentFragment::create($name, $fragmentHtml);
}
}
return FragmentCollection::fromFragments($fragments);
}
/**
* Check if HTML contains specific fragment
*/
public function hasFragment(string $html, string $fragmentName): bool
{
if (empty(trim($html))) {
return false;
}
$wrapper = $this->parser->parseToWrapper($html);
return $this->extractFragment($wrapper, $fragmentName) !== null;
}
/**
* Get all fragment names from HTML
*
* @param string $html Full component HTML
* @return array<string> Fragment names found
*/
public function getFragmentNames(string $html): array
{
if (empty(trim($html))) {
return [];
}
$wrapper = $this->parser->parseToWrapper($html);
$elementCollection = $wrapper->getElementsByAttribute('data-lc-fragment');
if ($elementCollection->isEmpty()) {
return [];
}
$names = [];
foreach ($elementCollection->all() as $element) {
$name = $element->getAttribute('data-lc-fragment');
if (! empty($name)) {
$names[] = $name;
}
}
return array_unique($names);
}
/**
* Extract single fragment from DomWrapper
*/
private function extractFragment(DomWrapper $wrapper, string $fragmentName): ?string
{
// Find element with specific data-lc-fragment attribute value
$elementCollection = $wrapper->getElementsByAttribute('data-lc-fragment', $fragmentName);
if ($elementCollection->isEmpty()) {
return null;
}
// Get first matching element
$element = $elementCollection->first();
if ($element === null) {
return null;
}
return $this->elementToHtml($element);
}
/**
* Convert DOM element to HTML string
*/
private function elementToHtml(Element $element): string
{
// Get outer HTML of element (includes the element itself)
return $element->ownerDocument->saveHTML($element);
}
}

View File

@@ -0,0 +1,109 @@
<?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);
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Framework\LiveComponents\Rendering;
use App\Framework\Attributes\Initializer;
use App\Framework\DI\Container;
use App\Framework\Template\Parser\DomTemplateParser;
use App\Framework\View\LiveComponentRenderer;
/**
* Fragment Renderer Initializer
*
* Registers FragmentRenderer in DI container with all dependencies.
*/
final readonly class FragmentRendererInitializer
{
#[Initializer]
public function __invoke(Container $container): FragmentRenderer
{
$componentRenderer = $container->get(LiveComponentRenderer::class);
$templateParser = $container->get(DomTemplateParser::class);
// Create FragmentExtractor
$fragmentExtractor = new FragmentExtractor($templateParser);
// Create FragmentRenderer
return new FragmentRenderer($componentRenderer, $fragmentExtractor);
}
}