Add type-safe wrapper around json_encode
This commit is contained in:
		
							
								
								
									
										19
									
								
								MD_STD.php
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								MD_STD.php
									
									
									
									
									
								
							@@ -115,6 +115,25 @@ class MD_STD {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Type-safe wrapper around json_encode.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @see https://www.php.net/manual/en/function.json-encode.php
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param array<mixed> $value   The value being encoded. Can be any type except a resource.
 | 
				
			||||||
 | 
					     * @param integer      $options Bitmask consisting of JSON_FORCE_OBJECT, JSON_HEX_QUOT ...
 | 
				
			||||||
 | 
					     * @param integer      $depth   Depth of coding.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static function json_encode(array $value, int $options = 0, int $depth = 512):string {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $output = json_encode($value, $options, $depth);
 | 
				
			||||||
 | 
					        if ($output === false) throw new Exception("JSON output could not be generated");
 | 
				
			||||||
 | 
					        return $output;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Wrapper for curling contents from the web.
 | 
					     * Wrapper for curling contents from the web.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user