| 
									
										
										
										
											2022-08-16 20:23:53 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-17 21:39:53 +08:00
										 |  |  | namespace BookStack\References\ModelResolvers; | 
					
						
							| 
									
										
										
										
											2022-08-16 20:23:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | use BookStack\Entities\Models\Page; | 
					
						
							|  |  |  | use BookStack\Model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PagePermalinkModelResolver implements CrossLinkModelResolver | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function resolve(string $link): ?Model | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $pattern = '/^' . preg_quote(url('/link'), '/') . '\/(\d+)/'; | 
					
						
							|  |  |  |         $matches = []; | 
					
						
							|  |  |  |         $match = preg_match($pattern, $link, $matches); | 
					
						
							|  |  |  |         if (!$match) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $id = intval($matches[1]); | 
					
						
							|  |  |  |         /** @var ?Page $model */ | 
					
						
							| 
									
										
										
										
											2022-08-17 23:59:23 +08:00
										 |  |  |         $model = Page::query()->find($id, ['id']); | 
					
						
							| 
									
										
										
										
											2022-08-16 20:23:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $model; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-08-30 00:46:41 +08:00
										 |  |  | } |