Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace YakNet\AccessibilityConsole\Parser;
|
|
|
|
class TemplatePreprocessor
|
|
{
|
|
private BladeParser $bladeParser;
|
|
private TwigParser $twigParser;
|
|
private HtmlParser $htmlParser;
|
|
|
|
public function __construct(
|
|
?BladeParser $bladeParser = null,
|
|
?TwigParser $twigParser = null,
|
|
?HtmlParser $htmlParser = null
|
|
) {
|
|
$this->bladeParser = $bladeParser ?? new BladeParser();
|
|
$this->twigParser = $twigParser ?? new TwigParser();
|
|
$this->htmlParser = $htmlParser ?? new HtmlParser();
|
|
}
|
|
|
|
/**
|
|
* Preprocess file content according to its file extension or template dialect.
|
|
*
|
|
* @param string $content
|
|
* @param string|null $filePath
|
|
* @return string
|
|
*/
|
|
public function preprocess(string $content, ?string $filePath = null): string
|
|
{
|
|
if ($filePath !== null) {
|
|
$lower = strtolower($filePath);
|
|
if (str_ends_with($lower, '.blade.php')) {
|
|
return $this->bladeParser->parse($content);
|
|
}
|
|
if (str_ends_with($lower, '.twig')) {
|
|
return $this->twigParser->parse($content);
|
|
}
|
|
if (str_ends_with($lower, '.php')) {
|
|
return $this->preprocessPhp($content);
|
|
}
|
|
}
|
|
|
|
// Detect Blade or Twig by content heuristic if no path is provided
|
|
if (str_contains($content, '{{') || str_contains($content, '@if') || str_contains($content, '@foreach')) {
|
|
return $this->bladeParser->parse($content);
|
|
}
|
|
|
|
if (str_contains($content, '{%') || str_contains($content, '{#')) {
|
|
return $this->twigParser->parse($content);
|
|
}
|
|
|
|
if (str_contains($content, '<' . '?php') || str_contains($content, '<' . '?=')) {
|
|
return $this->preprocessPhp($content);
|
|
}
|
|
|
|
return $this->htmlParser->parse($content);
|
|
}
|
|
|
|
private function preprocessPhp(string $content): string
|
|
{
|
|
// Replace short echo tags with placeholder text preserving newlines
|
|
$content = preg_replace_callback('/<\?=(.*?)\?>/s', function ($m) {
|
|
$newlines = str_repeat("\n", substr_count($m[0], "\n"));
|
|
return 'StaticPhpEcho' . $newlines;
|
|
}, $content) ?? $content;
|
|
|
|
// Replace PHP execution blocks with placeholder preserving newlines
|
|
$content = preg_replace_callback('/<\?php(.*?)\?>/s', function ($m) {
|
|
return str_repeat("\n", substr_count($m[0], "\n"));
|
|
}, $content) ?? $content;
|
|
|
|
return $content;
|
|
}
|
|
}
|