Skip to content

Instantly share code, notes, and snippets.

@kemo
Created June 17, 2011 09:03
Show Gist options
  • Save kemo/1031103 to your computer and use it in GitHub Desktop.
Save kemo/1031103 to your computer and use it in GitHub Desktop.
and_where_open() / or_where_open() auto removal example
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Database_Query_Builder_Where extends Kohana_Database_Query_Builder_Where {
/**
* Closes an open "AND WHERE (...)" grouping.
*
* @return $this
*/
public function and_where_close()
{
$copy = end($this->_where);
if (end($copy) === '(')
{
array_pop($this->_where);
}
else
{
$this->_where[] = array('AND' => ')');
}
return $this;
}
/**
* Closes an open "OR WHERE (...)" grouping.
*
* @return $this
*/
public function or_where_close()
{
$copy = end($this->_where);
if (end($copy) === '(')
{
array_pop($this->_where);
}
else
{
$this->_where[] = array('OR' => ')');
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment