mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Zip Exports: Added attachment/image link resolving & JSON null handling
This commit is contained in:
22
app/References/ModelResolvers/AttachmentModelResolver.php
Normal file
22
app/References/ModelResolvers/AttachmentModelResolver.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\References\ModelResolvers;
|
||||
|
||||
use BookStack\Uploads\Attachment;
|
||||
|
||||
class AttachmentModelResolver implements CrossLinkModelResolver
|
||||
{
|
||||
public function resolve(string $link): ?Attachment
|
||||
{
|
||||
$pattern = '/^' . preg_quote(url('/attachments'), '/') . '\/(\d+)/';
|
||||
$matches = [];
|
||||
$match = preg_match($pattern, $link, $matches);
|
||||
if (!$match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id = intval($matches[1]);
|
||||
|
||||
return Attachment::query()->find($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user