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.

25 lines
604 B

  1. <?php
  2. function json_response(&$app, $response, $code=200) {
  3. $app->response()->status($code);
  4. $app->response()['Content-Type'] = 'application/json';
  5. $app->response()->body(json_encode($response));
  6. }
  7. function k($a, $k, $default=null) {
  8. if(is_array($k)) {
  9. $result = true;
  10. foreach($k as $key) {
  11. $result = $result && array_key_exists($key, $a);
  12. }
  13. return $result;
  14. } else {
  15. if(is_array($a) && array_key_exists($k, $a) && $a[$k])
  16. return $a[$k];
  17. elseif(is_object($a) && property_exists($a, $k) && $a->$k)
  18. return $a->$k;
  19. else
  20. return $default;
  21. }
  22. }