| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 09:26:18 +01:00
										 |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  | namespace Plugin\ActivityPub\Util\Response; | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 03:22:27 +01:00
										 |  |  | use App\Entity\Actor; | 
					
						
							| 
									
										
										
										
											2021-11-16 23:24:06 +00:00
										 |  |  | use App\Util\Exception\ClientException; | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  | use Exception; | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  | use Plugin\ActivityPub\Util\Model\EntityToType\GSActorToType; | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | abstract class ActorResponse | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-10-10 09:26:18 +01:00
										 |  |  |      * @param int $status The response status code | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2021-09-18 03:22:27 +01:00
										 |  |  |      *@throws Exception | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-18 03:22:27 +01:00
										 |  |  |     public static function handle(Actor $gsactor, int $status = 200): TypeResponse | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-16 23:24:06 +00:00
										 |  |  |         if ($gsactor->getIsLocal()) { | 
					
						
							|  |  |  |             return new TypeResponse(data: GSActorToType::translate($gsactor), status: $status); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             throw new ClientException('This is a remote actor, you should request it to its source of authority instead.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-14 17:15:37 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-10 09:26:18 +01:00
										 |  |  | } |