mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-03 02:13:16 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			523 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			523 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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);
 | 
						|
    }
 | 
						|
}
 |