41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Support;
|
||
|
|
|
||
|
|
use Modules\Core\Store\Services\StoreDetailsService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {placeholder} => StoreDetails column, usable in Stoic markdown (legal pages,
|
||
|
|
* FAQ answers).
|
||
|
|
*/
|
||
|
|
class StorePlaceholders
|
||
|
|
{
|
||
|
|
private const PLACEHOLDERS = [
|
||
|
|
'{store_name}' => 'name',
|
||
|
|
'{store_address}' => 'address',
|
||
|
|
'{store_phone}' => 'phone',
|
||
|
|
'{store_contact_email}' => 'contact_email',
|
||
|
|
'{store_legal_name}' => 'legal_name',
|
||
|
|
'{store_tax_identifier}' => 'tax_identifier',
|
||
|
|
'{store_registration_number}' => 'registration_number',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
private readonly StoreDetailsService $storeDetails,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Swapped in before the markdown is rendered, so values are escaped: the
|
||
|
|
* rendered markdown is printed unescaped. An empty field renders as
|
||
|
|
* nothing rather than leaving the raw placeholder on the page.
|
||
|
|
*/
|
||
|
|
public function fill(string $content): string
|
||
|
|
{
|
||
|
|
$details = $this->storeDetails->current();
|
||
|
|
|
||
|
|
return strtr($content, array_map(
|
||
|
|
fn (string $column) => e((string) ($details->translate($column) ?? '')),
|
||
|
|
self::PLACEHOLDERS,
|
||
|
|
));
|
||
|
|
}
|
||
|
|
}
|