Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /**
  2. * Helper: Provides that only meant database fields are changed.
  3. *
  4. * @param array $fields Fields (key, value pairs)
  5. * @param array $expected Changeable fields (just keys)
  6. * @throws HTTP_Exception_400 If any key of 1st array is not found in 2nd array, but is table column
  7. */
  8. function check_fields($fields, $changeable) {
  9.  
  10. $field_keys = array_keys($fields);
  11. $column_keys = array_keys($this->_data);
  12.  
  13. foreach ($field_keys as $key) {
  14.  
  15. if (is_array($fields[$key])) {
  16.  
  17. $this->check_fields($fields[$key], $changeable[$key]);
  18.  
  19. }
  20.  
  21. if (!in_array($key, $changeable) && in_array($key, $column_keys)) {
  22.  
  23. throw new HTTP_Exception_400("Trying to change database fields that aren't meant to be changed!");
  24.  
  25. }
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement