Skip to content

Instantly share code, notes, and snippets.

@pfefferle
Forked from aaronpk/is_valid_mf2_json.php
Created August 19, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfefferle/1bf67087d92b22d61f37bd0f67dc0bb5 to your computer and use it in GitHub Desktop.
Save pfefferle/1bf67087d92b22d61f37bd0f67dc0bb5 to your computer and use it in GitHub Desktop.
<?php
function is_valid_mf2_json($input) {
// Input to this function must be an array
if(!is_array($input))
return false;
// Keys type and properties are required at a minimum and must be arrays
if(!isset($input['type']) || !is_array($input['type']))
return false;
if(!isset($input['properties']) || !is_array($input['properties']))
return false;
// Every value of type must be a string beginning with h-
foreach($input['type'] as $type) {
if(!is_string($type) || substr($type, 0, 2) != 'h-')
return false;
}
foreach($input['properties'] as $property) {
// Every property must be an array
if(!is_array($property))
return false;
// If a value of a property is not a string, it must be a valid mf2 object
foreach($property as $val) {
if(!is_string($val)) {
if(!is_valid_mf2_json($val))
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment