mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 12:02:30 +01:00 
			
		
		
		
	Added an example code
This commit is contained in:
		
							
								
								
									
										18
									
								
								example/main.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								example/main.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| use Gitea\{PushEvent}; | ||||
|  | ||||
| /** | ||||
|  * Handles the payload of a Gitea push event. | ||||
|  * @return PushEvent The parsed payload. | ||||
|  * @throws UnexpectedValueException The request headers or the request body are invalid. | ||||
|  */ | ||||
| function main(): PushEvent { | ||||
|   if (!isset($_SERVER['HTTP_X_GITEA_DELIVERY']) || !isset($_SERVER['HTTP_X_GITEA_EVENT'])) | ||||
|     throw new UnexpectedValueException('Invalid payload data.'); | ||||
|  | ||||
|   $data = json_decode((string) file_get_contents('php://input')); | ||||
|   if (!is_object($data)) throw new UnexpectedValueException('Invalid payload data.'); | ||||
|  | ||||
|   return PushEvent::fromJson($data); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user