add all controllers logic
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Policy;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PolicyContentService
|
||||
{
|
||||
private const TYPES = [
|
||||
'school' => 'school_policy.html',
|
||||
'picture' => 'picture_policy.html',
|
||||
];
|
||||
|
||||
public function getPolicy(string $type): array
|
||||
{
|
||||
$type = strtolower(trim($type));
|
||||
if (!isset(self::TYPES[$type])) {
|
||||
throw new \InvalidArgumentException('Unsupported policy type.');
|
||||
}
|
||||
|
||||
$filename = self::TYPES[$type];
|
||||
$path = resource_path('policies/' . $filename);
|
||||
|
||||
if (!is_file($path)) {
|
||||
Log::warning('Policy file missing.', ['type' => $type, 'path' => $path]);
|
||||
return [
|
||||
'type' => $type,
|
||||
'title' => $this->titleFor($type),
|
||||
'content' => '',
|
||||
'format' => 'html',
|
||||
'source' => $path,
|
||||
'updated_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => $type,
|
||||
'title' => $this->titleFor($type),
|
||||
'content' => (string) file_get_contents($path),
|
||||
'format' => 'html',
|
||||
'source' => $path,
|
||||
'updated_at' => date('Y-m-d H:i:s', filemtime($path)),
|
||||
];
|
||||
}
|
||||
|
||||
private function titleFor(string $type): string
|
||||
{
|
||||
return $type === 'picture' ? 'Picture Policy' : 'School Policy';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user