Skip to content

Instantly share code, notes, and snippets.

@burzum
Created March 19, 2019 11:18
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 burzum/fd0a7571b258000a1ee9d44c0c41cfb2 to your computer and use it in GitHub Desktop.
Save burzum/fd0a7571b258000a1ee9d44c0c41cfb2 to your computer and use it in GitHub Desktop.
Query.php
public function applyOptions(array $options)
{
$valid = [
'fields' => 'select',
'conditions' => 'where',
'join' => 'join',
'order' => 'order',
'limit' => 'limit',
'offset' => 'offset',
'group' => 'group',
'having' => 'having',
'contain' => 'contain',
'page' => 'page',
];
ksort($options);
foreach ($options as $option => $values) {
if (isset($valid[$option], $values)) {
if (strstr($valid[$option], 'order')) {
$this->{$valid[$option]}($values, true);
} else {
$this->{$valid[$option]}($values);
}
} else {
$this->_options[$option] = $values;
}
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment