Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ src/Core/View/
├── Compiler.php # Compila templates
├── Parser.php # Parser da AST
├── Lexer.php # Tokenizador
├── Renderer.php # Renderizador
├── Renderer.php # Renderização via include (sem eval)
├── Environment.php # Configuração
├── Nodes/ # AST Nodes
├── Directives/ # Processadores de tags
├── Filters/ # Filtros
├── TemplateResolver.php # Resolução segura de caminhos
├── Abstract/ # Bases abstratas (Node/Directive/Filter/Middleware)
├── Nodes/ # AST nodes compiláveis
├── Directives/ # Registry + directives padrão
├── Filters/ # Filtros por domínio + registry
├── Scope/ # Scope e pilha de variáveis
├── Layout/ # Herança de templates e blocos
├── Cache/ # Cache key + file watcher
├── Escape/ # Escape context-aware (HTML/JS/CSS/URI)
├── Middleware/ # Pipeline de middlewares
├── Validation/ # Validação de sintaxe/template
├── Debug/ # Source/runtime debugging helpers
├── Components/ # Sistema de componentes
├── Cache/ # Cache
└── Exceptions/ # Exceções
└── Exceptions/ # Hierarquia de exceções
```

## Contribuindo
Expand Down
11 changes: 11 additions & 0 deletions src/Core/View/Abstract/AbstractDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Beobles\Core\View\Abstract;

abstract class AbstractDirective
{
abstract public function getName(): string;

/** @return array<string, mixed> */
abstract public function parseAttributes(string $attributes): array;
}
15 changes: 15 additions & 0 deletions src/Core/View/Abstract/AbstractFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Beobles\Core\View\Abstract;

abstract class AbstractFilter
{
abstract public function getName(): string;

public function __invoke(mixed $value, mixed ...$args): mixed
{
return $this->apply($value, ...$args);
}

abstract public function apply(mixed $value, mixed ...$args): mixed;
}
12 changes: 12 additions & 0 deletions src/Core/View/Abstract/AbstractMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Beobles\Core\View\Abstract;

abstract class AbstractMiddleware
{
/**
* @param callable(array<string, mixed>): string $next
* @param array<string, mixed> $context
*/
abstract public function handle(array $context, callable $next): string;
}
42 changes: 42 additions & 0 deletions src/Core/View/Abstract/AbstractNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Beobles\Core\View\Abstract;

use Beobles\Core\View\Compiler;
use Beobles\Core\View\Nodes\NodeInterface;

abstract class AbstractNode implements NodeInterface
{
protected int $line;
protected int $column;
protected array $metadata;

public function __construct(int $line = 1, int $column = 1, array $metadata = [])
{
$this->line = $line;
$this->column = $column;
$this->metadata = $metadata;
}

abstract public function compile(Compiler $compiler): string;

public function accept(callable $visitor)
{
return $visitor($this);
}

public function getLine(): int
{
return $this->line;
}

public function getColumn(): int
{
return $this->column;
}

public function getMetadata(): array
{
return $this->metadata;
}
}
20 changes: 20 additions & 0 deletions src/Core/View/Cache/CacheKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Beobles\Core\View\Cache;

class CacheKey
{
/** @param array<int, string> $dependencies */
public function forTemplate(string $path, array $dependencies = []): string
{
$signature = $path;
foreach ($dependencies as $dep) {
$signature .= '|' . $dep;
if (is_file($dep)) {
$signature .= ':' . (string) filemtime($dep);
}
}

return 'template_' . md5($signature);
}
}
25 changes: 25 additions & 0 deletions src/Core/View/Cache/FileWatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Beobles\Core\View\Cache;

class FileWatcher
{
/** @var array<string, int|false> */
private array $mtimes = [];

/** @param array<int, string> $paths */
public function hasChanged(array $paths): bool
{
$changed = false;

foreach ($paths as $path) {
$mtime = is_file($path) ? filemtime($path) : false;
if (!array_key_exists($path, $this->mtimes) || $this->mtimes[$path] !== $mtime) {
$changed = true;
$this->mtimes[$path] = $mtime;
}
}

return $changed;
}
}
Loading