You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SmartFit_API/app/helpers.php

32 lines
694 B

<?php
class Helpers
{
static public function validJson(string $json, array $keys): bool
{
if (Helpers::isJson($json)) {
if (!Helpers::expectedArrayKeys(json_decode($json, true), $keys)) {
return false;
}
return true;
}
return false;
}
static public function isJson(string $json): bool
{
json_decode($json);
return json_last_error() === JSON_ERROR_NONE;
}
static public function expectedArrayKeys(array $json, array $keys): bool
{
foreach ($keys as $key) {
if (!array_key_exists($key, $json)) return false;
}
return true;
}
}