2025-04-27 16:38:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
|
|
class MicropubRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
// Validation rules
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-24 22:26:41 +01:00
|
|
|
/**
|
|
|
|
|
* Determine the request type: the action (e.g. "update") if one is given,
|
|
|
|
|
* otherwise the microformat type without its "h-" prefix. Per the spec, a
|
|
|
|
|
* request with no type is treated as an h-entry.
|
|
|
|
|
*/
|
2025-04-27 16:38:25 +01:00
|
|
|
public function getType(): ?string
|
|
|
|
|
{
|
|
|
|
|
if ($this->isJson()) {
|
2026-03-13 20:39:50 +00:00
|
|
|
$data = $this->json()->all();
|
2025-04-27 16:38:25 +01:00
|
|
|
|
2026-10-24 22:26:41 +01:00
|
|
|
if (isset($data['action']) && is_string($data['action'])) {
|
|
|
|
|
return $data['action'];
|
2025-04-27 16:38:25 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 20:39:50 +00:00
|
|
|
if (isset($data['type']) && is_array($data['type'])) {
|
|
|
|
|
$type = current($data['type']);
|
2026-10-24 22:26:41 +01:00
|
|
|
if (is_string($type) && str_starts_with($type, 'h-')) {
|
2026-03-13 20:39:50 +00:00
|
|
|
return substr($type, 2);
|
|
|
|
|
}
|
2026-10-24 22:26:41 +01:00
|
|
|
|
|
|
|
|
return null;
|
2026-03-13 20:39:50 +00:00
|
|
|
}
|
2025-04-27 16:38:25 +01:00
|
|
|
|
2026-10-24 22:26:41 +01:00
|
|
|
return 'entry';
|
2025-08-17 11:05:38 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-24 22:26:41 +01:00
|
|
|
if ($this->filled('action')) {
|
|
|
|
|
return $this->input('action');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->input('h') ?: 'entry';
|
2025-08-17 11:05:38 +01:00
|
|
|
}
|
2025-04-27 16:38:25 +01:00
|
|
|
}
|