v7.0.0-beta.2 release

This commit is contained in:
HeuJung committed 2026-04-20 20:37:49 +09:00
1 parent 6595fd0eb5
commit fa8eba7a0d
1165 files changed
+107118 -762127

No files matched your search

+29 -19
View File
@@ -2,21 +2,23 @@
namespace App\Seo;
use App\Contracts\Extension\CacheInterface;
use App\Seo\Contracts\SeoCacheManagerInterface;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class SeoCacheManager implements SeoCacheManagerInterface
{
/**
* 캐시 키 프리픽스
* 캐시 키 프리픽스 (드라이버 접두사 `g7:core:` 다음에 붙음)
*/
private const CACHE_PREFIX = 'seo:page:';
private const CACHE_PREFIX = 'seo.page.';
/**
* 캐시된 URL 인덱스 키
*/
private const INDEX_KEY = 'seo:cached_urls';
private const INDEX_KEY = 'seo.cached_urls';
public function __construct(private readonly CacheInterface $cache) {}
/**
* {@inheritdoc}
@@ -29,7 +31,7 @@ class SeoCacheManager implements SeoCacheManagerInterface
$key = $this->buildKey($url, $locale);
return Cache::get($key);
return $this->cache->get($key);
}
/**
@@ -42,9 +44,9 @@ class SeoCacheManager implements SeoCacheManagerInterface
}
$key = $this->buildKey($url, $locale);
$ttl = (int) g7_core_settings('seo.cache_ttl', 7200);
$ttl = $this->getCacheTtl();
Cache::put($key, $html, $ttl);
$this->cache->put($key, $html, $ttl);
// URL 인덱스 업데이트
$this->addToIndex($url, $locale, $key);
@@ -60,7 +62,7 @@ class SeoCacheManager implements SeoCacheManagerInterface
foreach ($index as $entry) {
if ($this->matchesPattern($entry['url'], $urlPattern)) {
Cache::forget($entry['key']);
$this->cache->forget($entry['key']);
$count++;
}
}
@@ -82,7 +84,7 @@ class SeoCacheManager implements SeoCacheManagerInterface
foreach ($index as $entry) {
if (($entry['layout'] ?? '') === $layoutName) {
Cache::forget($entry['key']);
$this->cache->forget($entry['key']);
$count++;
}
}
@@ -102,10 +104,10 @@ class SeoCacheManager implements SeoCacheManagerInterface
$index = $this->getIndex();
foreach ($index as $entry) {
Cache::forget($entry['key']);
$this->cache->forget($entry['key']);
}
Cache::forget(self::INDEX_KEY);
$this->cache->forget(self::INDEX_KEY);
Log::info('[SEO] All cache cleared', ['count' => count($index)]);
}
@@ -135,7 +137,15 @@ class SeoCacheManager implements SeoCacheManagerInterface
*/
private function isEnabled(): bool
{
return (bool) g7_core_settings('seo.cache_enabled', true);
return (bool) g7_core_settings('cache.seo_enabled', g7_core_settings('seo.cache_enabled', true));
}
/**
* 캐시 TTL (초) — g7_core_settings('cache.seo_ttl') 우선.
*/
private function getCacheTtl(): int
{
return (int) g7_core_settings('cache.seo_ttl', g7_core_settings('seo.cache_ttl', 7200));
}
/**
@@ -155,7 +165,7 @@ class SeoCacheManager implements SeoCacheManagerInterface
'cached_at' => now()->toIso8601String(),
];
Cache::put(self::INDEX_KEY, $index, 86400 * 30); // 30일
$this->cache->put(self::INDEX_KEY, $index, 86400 * 30); // 30일
}
/**
@@ -163,7 +173,7 @@ class SeoCacheManager implements SeoCacheManagerInterface
*/
private function getIndex(): array
{
return Cache::get(self::INDEX_KEY, []);
return $this->cache->get(self::INDEX_KEY, []);
}
/**
@@ -175,12 +185,12 @@ class SeoCacheManager implements SeoCacheManagerInterface
$validIndex = [];
foreach ($index as $key => $entry) {
if (Cache::has($entry['key'])) {
if ($this->cache->has($entry['key'])) {
$validIndex[$key] = $entry;
}
}
Cache::put(self::INDEX_KEY, $validIndex, 86400 * 30);
$this->cache->put(self::INDEX_KEY, $validIndex, 86400 * 30);
}
/**
@@ -212,9 +222,9 @@ class SeoCacheManager implements SeoCacheManagerInterface
}
$key = $this->buildKey($url, $locale);
$ttl = (int) g7_core_settings('seo.cache_ttl', 7200);
$ttl = $this->getCacheTtl();
Cache::put($key, $html, $ttl);
$this->cache->put($key, $html, $ttl);
// 레이아웃 정보 포함하여 인덱스 업데이트
$index = $this->getIndex();
@@ -226,6 +236,6 @@ class SeoCacheManager implements SeoCacheManagerInterface
'cached_at' => now()->toIso8601String(),
];
Cache::put(self::INDEX_KEY, $index, 86400 * 30);
$this->cache->put(self::INDEX_KEY, $index, 86400 * 30);
}
}
+8 -7
View File
@@ -2,10 +2,10 @@
namespace App\Seo;
use App\Contracts\Extension\CacheInterface;
use App\Contracts\Repositories\TemplateRepositoryInterface;
use App\Extension\ModuleManager;
use App\Extension\PluginManager;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class SeoConfigMerger
@@ -16,14 +16,15 @@ class SeoConfigMerger
private const CACHE_TTL = 86400;
/**
* 캐시 키 접두사
* 캐시 키 접두사 (드라이버 접두사 `g7:core:` 다음에 붙음)
*/
private const CACHE_PREFIX = 'seo:config:merged:';
private const CACHE_PREFIX = 'seo.config.';
public function __construct(
private readonly ModuleManager $moduleManager,
private readonly PluginManager $pluginManager,
private readonly TemplateRepositoryInterface $templateRepository,
private readonly CacheInterface $cache,
) {}
/**
@@ -38,9 +39,9 @@ class SeoConfigMerger
{
$cacheKey = self::CACHE_PREFIX.$templateIdentifier;
return Cache::remember($cacheKey, self::CACHE_TTL, function () use ($templateIdentifier) {
return $this->cache->remember($cacheKey, function () use ($templateIdentifier) {
return $this->buildMergedConfig($templateIdentifier);
});
}, self::CACHE_TTL, ['seo']);
}
/**
@@ -51,7 +52,7 @@ class SeoConfigMerger
public function clearCache(?string $templateIdentifier = null): void
{
if ($templateIdentifier !== null) {
Cache::forget(self::CACHE_PREFIX.$templateIdentifier);
$this->cache->forget(self::CACHE_PREFIX.$templateIdentifier);
return;
}
@@ -62,7 +63,7 @@ class SeoConfigMerger
try {
$templates = $this->templateRepository->getActive();
foreach ($templates as $template) {
Cache::forget(self::CACHE_PREFIX.$template->identifier);
$this->cache->forget(self::CACHE_PREFIX.$template->identifier);
}
} catch (\Throwable $e) {
Log::warning('[SEO] Config cache clear failed, clearing by pattern', [
+21 -3
View File
@@ -94,7 +94,16 @@ class SeoMetaResolver
return $pageSeoTitle;
}
// Tier 2: 모듈 설정 템플릿 (page_type 기반)
// Tier 2: _seo context (SeoRenderer가 extensions 기반으로 주입)
$pageType = $seoConfig['page_type'] ?? null;
if ($pageType) {
$seoTitle = data_get($context, "_seo.{$pageType}.title", '');
if ($seoTitle !== '') {
return $seoTitle;
}
}
// Tier 2 하위호환: moduleIdentifier/pluginIdentifier 기반 (extensions 미선언 시)
if ($moduleIdentifier) {
$templateTitle = $this->resolveModuleTemplate($moduleIdentifier, 'title', $seoConfig, $context);
if ($templateTitle !== '') {
@@ -134,7 +143,16 @@ class SeoMetaResolver
return $pageSeoDesc;
}
// Tier 2: 모듈 설정 템플릿 (page_type 기반)
// Tier 2: _seo context (SeoRenderer가 extensions 기반으로 주입)
$pageType = $seoConfig['page_type'] ?? null;
if ($pageType) {
$seoDesc = data_get($context, "_seo.{$pageType}.description", '');
if ($seoDesc !== '') {
return $seoDesc;
}
}
// Tier 2 하위호환: moduleIdentifier/pluginIdentifier 기반 (extensions 미선언 시)
if ($moduleIdentifier) {
$templateDesc = $this->resolveModuleTemplate($moduleIdentifier, 'description', $seoConfig, $context);
if ($templateDesc !== '') {
@@ -214,8 +232,8 @@ class SeoMetaResolver
return (string) $value;
}
}
return '';
}
/**
+190
View File
@@ -2,6 +2,8 @@
namespace App\Seo;
use App\Contracts\Extension\ModuleManagerInterface;
use App\Contracts\Extension\PluginManagerInterface;
use App\Extension\HookManager;
use App\Seo\Contracts\SeoRendererInterface;
use App\Services\LayoutService;
@@ -25,6 +27,8 @@ class SeoRenderer implements SeoRendererInterface
private readonly SeoConfigMerger $seoConfigMerger,
private readonly SettingsService $settingsService,
private readonly PluginSettingsService $pluginSettingsService,
private readonly ModuleManagerInterface $moduleManager,
private readonly PluginManagerInterface $pluginManager,
) {}
/**
@@ -207,6 +211,12 @@ class SeoRenderer implements SeoRendererInterface
$this->htmlMapper->setSeoVars($resolvedVars);
}
// 5.96. meta.seo.extensions 기반 _seo context 주입
// extensions 배열에 선언된 확장의 seoVariables()를 수집하고
// 자동 해석 변수(setting/core_setting/query/route) + data 변수(vars 매핑)를 처리하여
// 설정 템플릿(meta_{page_type}_title/description)에 적용한 결과를 _seo.{page_type}에 주입
$this->resolveSeoContext($seoConfig, $context, $routeParams, $resolvedVars ?? []);
// 6. SeoMetaResolver로 3계층 캐스케이드 메타 해석
$meta = $this->metaResolver->resolve($seoConfig, $context, $moduleIdentifier, $pluginIdentifier, $routeParams);
@@ -547,6 +557,10 @@ class SeoRenderer implements SeoRendererInterface
$global['settings'] = [];
}
// 코어 설정에서 사이트 기본 정보 주입 (structured_data 등에서 참조)
$global['site_name'] = g7_core_settings('general.site_name', '');
$global['site_url'] = g7_core_settings('general.site_url', url('/'));
// modules: 모듈별 설정 (config에서 로드)
$global['modules'] = config('g7_settings.modules', []);
@@ -780,4 +794,180 @@ class SeoRenderer implements SeoRendererInterface
return $value;
}
/**
* meta.seo.extensions 기반으로 SEO 변수를 해석하고 _seo context에 주입합니다.
*
* 처리 흐름:
* 1. extensions 배열에서 확장 인스턴스 조회 → seoVariables() 수집
* 2. 자동 해석 변수(setting/core_setting/query/route) 처리
* 3. data 변수: meta.seo.vars 매핑 결과 사용 (이미 resolveSeoVars에서 해석됨)
* 4. 확장 설정 템플릿(meta_{page_type}_title/description) 조회 → {var} 치환
* 5. 결과를 context['_seo'][$pageType] = ['title' => ..., 'description' => ...] 주입
*
* @param array $seoConfig 레이아웃 meta.seo 설정
* @param array &$context 데이터 컨텍스트 (참조 전달 — _seo 주입)
* @param array $routeParams 라우트 파라미터
* @param array $resolvedVars 이미 해석된 vars (resolveSeoVars 결과)
*/
private function resolveSeoContext(array $seoConfig, array &$context, array $routeParams, array $resolvedVars): void
{
$extensions = $seoConfig['extensions'] ?? [];
$pageType = $seoConfig['page_type'] ?? null;
if (empty($extensions) || ! $pageType) {
return;
}
// 확장별 seoVariables() 수집 및 해석
$allResolvedVars = [];
foreach ($extensions as $extDef) {
$extType = $extDef['type'] ?? null;
$extId = $extDef['id'] ?? null;
if (! $extType || ! $extId) {
continue;
}
// 확장 인스턴스 조회
$extInstance = $this->getExtensionInstance($extType, $extId);
if (! $extInstance) {
continue;
}
$seoVarsDef = $extInstance->seoVariables();
if (empty($seoVarsDef)) {
continue;
}
// _common + page_type별 변수 병합
$commonVars = $seoVarsDef['_common'] ?? [];
$pageTypeVars = $seoVarsDef[$pageType] ?? [];
$mergedVarsDef = array_merge($commonVars, $pageTypeVars);
if (empty($mergedVarsDef)) {
continue;
}
// 변수 자동 해석
foreach ($mergedVarsDef as $varName => $varDef) {
$source = $varDef['source'] ?? 'data';
$key = $varDef['key'] ?? $varName;
$resolved = match ($source) {
'setting' => $this->resolveSettingVar($extType, $extId, $key),
'core_setting' => (string) g7_core_settings($key, ''),
'query' => (string) request()->query($key, ''),
'route' => (string) ($routeParams[$key] ?? ''),
'data' => $resolvedVars[$varName] ?? '',
default => '',
};
// required인데 값이 비어있으면 경고
if (($varDef['required'] ?? false) && $resolved === '') {
Log::warning('[SEO] Required variable not resolved', [
'variable' => $varName,
'page_type' => $pageType,
'extension' => $extId,
]);
}
$allResolvedVars[$varName] = $resolved;
}
// 설정 템플릿 해석 (확장별)
$this->applySettingsTemplate($extType, $extId, $pageType, $allResolvedVars, $context);
}
}
/**
* 확장 설정의 메타 템플릿을 해석하여 _seo context에 주입합니다.
*
* @param string $extType 확장 타입 ('module' 또는 'plugin')
* @param string $extId 확장 식별자
* @param string $pageType 페이지 타입
* @param array $vars 해석된 변수 맵
* @param array &$context 데이터 컨텍스트 (참조)
*/
private function applySettingsTemplate(string $extType, string $extId, string $pageType, array $vars, array &$context): void
{
$titleTemplate = (string) ($this->getExtensionSetting($extType, $extId, "seo.meta_{$pageType}_title") ?? '');
$descTemplate = (string) ($this->getExtensionSetting($extType, $extId, "seo.meta_{$pageType}_description") ?? '');
$title = $this->substituteVars($titleTemplate, $vars);
$description = $this->substituteVars($descTemplate, $vars);
if ($title !== '' || $description !== '') {
$context['_seo'][$pageType] = [
'title' => $title,
'description' => $description,
];
}
}
/**
* 설정 변수(source: setting)를 해석합니다.
*
* @param string $extType 확장 타입
* @param string $extId 확장 식별자
* @param string $key 설정 키
* @return string 해석된 값
*/
private function resolveSettingVar(string $extType, string $extId, string $key): string
{
return (string) $this->getExtensionSetting($extType, $extId, $key);
}
/**
* 확장 설정 값을 타입에 따라 조회합니다.
*
* @param string $extType 확장 타입 ('module' 또는 'plugin')
* @param string $extId 확장 식별자
* @param string $key 설정 키
* @return mixed 설정 값
*/
private function getExtensionSetting(string $extType, string $extId, string $key): mixed
{
return $extType === 'module'
? g7_module_settings($extId, $key, '')
: g7_plugin_settings($extId, $key, '');
}
/**
* 확장 인스턴스를 조회합니다.
*
* @param string $extType 확장 타입 ('module' 또는 'plugin')
* @param string $extId 확장 식별자
* @return object|null 확장 인스턴스
*/
private function getExtensionInstance(string $extType, string $extId): ?object
{
if ($extType === 'module') {
return $this->moduleManager->getModule($extId);
}
if ($extType === 'plugin') {
return $this->pluginManager->getPlugin($extId);
}
return null;
}
/**
* 템플릿 문자열 내 {변수명} 플레이스홀더를 치환합니다.
*
* @param string $template 템플릿 문자열 (예: "{commerce_name} - {product_name}")
* @param array $vars 변수 맵 (키 → 값)
* @return string 치환된 문자열
*/
private function substituteVars(string $template, array $vars): string
{
if ($template === '') {
return '';
}
return (string) preg_replace_callback('/\{(\w+)\}/', function ($matches) use ($vars) {
return $vars[$matches[1]] ?? $matches[0];
}, $template);
}
}