Newer
Older
function add($object, $at=false) {
if (!$object || !$object instanceof $this->model)
throw new Exception(__('Attempting to add invalid object to list'));
$object->set($this->key, $this->id);
if ($at !== false)
$this->cache[$at] = $object;
else
$this->cache[] = $object;
}
function remove($object) {
$object->delete();
}
function reset() {
$this->cache = array();
}
// QuerySet delegates
function count() {
return $this->queryset->count();
}
function exists() {
return $this->queryset->exists();
}
function expunge() {
if ($this->queryset->delete())
$this->reset();
function update(array $what) {
return $this->queryset->update($what);
}
// Fetch a new QuerySet
function objects() {
return clone $this->queryset;
function offsetUnset($a) {
$this->fillTo($a);
$this->cache[$a]->delete();
}
function offsetSet($a, $b) {
$this->fillTo($a);
$this->cache[$a]->delete();
$this->add($b, $a);
// QuerySet overriedes
function filter() {
return call_user_func_array(array($this->objects(), 'filter'), func_get_args());
}
function exclude() {
return call_user_func_array(array($this->objects(), 'exclude'), func_get_args());
}
function order_by() {
return call_user_func_array(array($this->objects(), 'order_by'), func_get_args());
}
function limit($how) {
return $this->objects()->limit($how);
}
var $joins = array();
var $aliases = array();
var $alias_num = 1;
function __construct($options=false) {
if ($options)
$this->options = array_merge($this->options, $options);
}
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
/**
* Handles breaking down a field or model search descriptor into the
* model search path, field, and operator parts. When used in a queryset
* filter, an expression such as
*
* user__email__hostname__contains => 'foobar'
*
* would be broken down to search from the root model (passed in,
* perhaps a ticket) to the user and email models by inspecting the
* model metadata 'joins' property. The 'constraint' value found there
* will be used to build the JOIN sql clauses.
*
* The 'hostname' will be the field on 'email' model that should be
* compared in the WHERE clause. The comparison should be made using a
* 'contains' function, which in MySQL, might be implemented using
* something like "<lhs> LIKE '%foobar%'"
*
* This function will rely heavily on the pushJoin() function which will
* handle keeping track of joins made previously in the query and
* therefore prevent multiple joins to the same table for the same
* reason. (Self joins are still supported).
*
* Comparison functions supported by this function are defined for each
* respective SqlCompiler subclass; however at least these functions
* should be defined:
*
* function a__function => b
* ----------+------------------------------------------------
* exact | a is exactly equal to b
* gt | a is greater than b
* lte | b is greater than a
* lt | a is less than b
* gte | b is less than a
* ----------+------------------------------------------------
* contains | (string) b is contained within a
* statswith | (string) first len(b) chars of a are exactly b
* endswith | (string) last len(b) chars of a are exactly b
* like | (string) a matches pattern b
* ----------+------------------------------------------------
* in | a is in the list or the nested queryset b
* ----------+------------------------------------------------
* isnull | a is null (if b) else a is not null
*
* If no comparison function is declared in the field descriptor,
* 'exact' is assumed.
*
* Parameters:
* $field - (string) name of the field to join
* $model - (VerySimpleModel) root model for references in the $field
* parameter
* $options - (array) extra options for the compiler
* 'table' => return the table alias rather than the field-name
* 'model' => return the target model class rather than the operator
* 'constraint' => extra constraint for join clause
*
* Returns:
* (mixed) Usually array<field-name, operator> where field-name is the
* name of the field in the destination model, and operator is the
* requestion comparison method.
*/
function getField($field, $model, $options=array()) {
// Break apart the field descriptor by __ (double-underbars). The
// first part is assumed to be the root field in the given model.
// The parts after each of the __ pieces are links to other tables.
// The last item (after the last __) is allowed to be an operator
// specifiction.
$parts = explode('__', $field);
$operator = static::$operators['exact'];
if (!isset($options['table'])) {
if (array_key_exists($field, static::$operators)) {
$operator = static::$operators[$field];
$field = array_pop($parts);
}
// Determine the alias for the root model table
$alias = (isset($this->joins['']))
? $this->joins['']['alias']
: $this->quote($model::$meta['table']);
// Call pushJoin for each segment in the join path. A new JOIN
// fragment will need to be emitted and/or cached
$push = function($p, $path, $extra=false) use (&$model) {
$model::_inspect();
if (!($info = $model::$meta['joins'][$p])) {
throw new OrmException(sprintf(
'Model `%s` does not have a relation called `%s`',
$model, $p));
}
$crumb = implode('__', $path);
$path[] = $p;
$tip = implode('__', $path);
$alias = $this->pushJoin($crumb, $tip, $model, $info, $extra);
// Roll to foreign model
foreach ($info['constraint'] as $local => $foreign) {
list($model, $f) = explode('.', $foreign);
if (class_exists($model))
break;
return array($alias, $f);
};
foreach ($parts as $i=>$p) {
list($alias) = $push($p, $path, @$options['constraint']);
$path[] = $p;
}
// If comparing a relationship, join the foreign table
// This is a comparison with a relationship — use the foreign key
if (isset($model::$meta['joins'][$field])) {
list($alias, $field) = $push($field, $path, @$options['constraint']);
if (isset($options['table']) && $options['table'])
elseif (isset($this->annotations[$field]))
$field = $this->annotations[$field];
elseif ($alias)
$field = $alias.'.'.$this->quote($field);
if (isset($options['model']) && $options['model'])
$operator = $model;
/**
* Uses the compiler-specific `compileJoin` function to compile the join
* statement fragment, and caches the result in the local $joins list. A
* new alias is acquired using the `nextAlias` function which will be
* associated with the join. If the same path is requested again, the
* algorithm is short-circuited and the originally-assigned table alias
* is returned immediately.
*/
function pushJoin($tip, $path, $model, $info, $constraint=false) {
// TODO: Build the join statement fragment and return the table
// alias. The table alias will be useful where the join is used in
// the WHERE and ORDER BY clauses
// If the join already exists for the statement-being-compiled, just
// return the alias being used.
if (!$constraint && isset($this->joins[$path]))
return $this->joins[$path]['alias'];
// TODO: Support only using aliases if necessary. Use actual table
// names for everything except oddities like self-joins
$alias = $this->nextAlias();
// Keep an association between the table alias and the model. This
// will make model construction much easier when we have the data
// and the table alias from the database.
$this->aliases[$alias] = $model;
// TODO: Stash joins and join constraints into local ->joins array.
// This will be useful metadata in the executor to construct the
// final models for fetching
// TODO: Always use a table alias. This will further help with
// coordination between the data returned from the database (where
// table alias is available) and the corresponding data.
$T = array('alias' => $alias);
$this->joins[$path] = &$T;
$T['sql'] = $this->compileJoin($tip, $model, $alias, $info, $constraint);
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
/**
* compileQ
*
* Build a constraint represented in an arbitrarily nested Q instance.
* The placement of the compiled constraint is also considered and
* represented in the resulting CompiledExpression instance.
*
* Parameters:
* $Q - (Q) constraint represented in a Q instance
* $model - (VerySimpleModel) root model for all the field references in
* the Q instance
* $slot - (int) slot for inputs to be placed. Useful to differenciate
* inputs placed in the joins and where clauses for SQL engines
* which do not support named parameters.
*
* Returns:
* (CompiledExpression) object containing the compiled expression (with
* AND, OR, and NOT operators added). Furthermore, the $type attribute
* of the CompiledExpression will allow the compiler to place the
* constraint properly in the WHERE or HAVING clause appropriately.
*/
function compileQ(Q $Q, $model, $slot=false) {
$type = CompiledExpression::TYPE_WHERE;
foreach ($Q->constraints as $field=>$value) {
// Handle nested constraints
if ($value instanceof Q) {
$filter[] = $T = $this->compileQ($value, $model, $slot);
// Bubble up HAVING constraints
if ($T instanceof CompiledExpression
&& $T->type == CompiledExpression::TYPE_HAVING)
$type = $T->type;
// Handle relationship comparisons with model objects
elseif ($value instanceof VerySimpleModel) {
$criteria = array();
foreach ($value->pk as $f=>$v) {
$f = $field . '__' . $f;
$criteria[$f] = $v;
}
$filter[] = $this->compileQ(new Q($criteria), $model, $slot);
}
// Handle simple field = <value> constraints
list($field, $op) = $this->getField($field, $model);
// This constraint has to go in the HAVING clause
$field = $field->toSql($this, $model);
$type = CompiledExpression::TYPE_HAVING;
}
if ($value === null)
$filter[] = sprintf('%s IS NULL', $field);
// Allow operators to be callable rather than sprintf
// strings
$filter[] = call_user_func($op, $field, $value, $model);
$filter[] = sprintf($op, $field, $this->input($value, $slot));
$glue = $Q->isOred() ? ' OR ' : ' AND ';
$clause = implode($glue, $filter);
if (count($filter) > 1)
$clause = '(' . $clause . ')';
if ($Q->isNegated())
$clause = 'NOT '.$clause;
return new CompiledExpression($clause, $type);
}
function compileConstraints($where, $model) {
$constraints = array();
foreach ($where as $Q) {
$constraints[] = $this->compileQ($Q, $model);
}
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
}
function getParams() {
return $this->params;
}
function getJoins() {
$sql = '';
foreach ($this->joins as $j)
$sql .= $j['sql'];
return $sql;
}
function nextAlias() {
// Use alias A1-A9,B1-B9,...
$alias = chr(65 + (int)($this->alias_num / 9)) . $this->alias_num % 9;
$this->alias_num++;
return $alias;
}
}
class CompiledExpression /* extends SplString */ {
const TYPE_WHERE = 0x0001;
const TYPE_HAVING = 0x0002;
var $text = '';
function __construct($clause, $type=self::TYPE_WHERE) {
$this->text = $clause;
$this->type = $type;
}
function __toString() {
return $this->text;
}
}
static $compiler = 'MySqlCompiler';
function __construct($info) {
}
function connect() {
}
// Gets a compiler compatible with this database engine that can compile
// and execute a queryset or DML request.
static function getCompiler() {
$class = static::$compiler;
return new $class();
static function delete(VerySimpleModel $model) {
return static::getCompiler()->compileDelete($model);
}
static function save(VerySimpleModel $model) {
$compiler = static::getCompiler();
if ($model->__new__)
return $compiler->compileInsert($model);
else
return $compiler->compileUpdate($model);
}
}
class MySqlCompiler extends SqlCompiler {
// Consts for ::input()
const SLOT_JOINS = 1;
const SLOT_WHERE = 2;
protected $input_join_count = 0;
static $operators = array(
'exact' => '%1$s = %2$s',
'contains' => array('self', '__contains'),
'gt' => '%1$s > %2$s',
'lt' => '%1$s < %2$s',
'gte' => '%1$s >= %2$s',
'lte' => '%1$s <= %2$s',
'isnull' => array('self', '__isnull'),
'in' => array('self', '__in'),
);
function __contains($a, $b) {
# {%a} like %{$b}%
return sprintf('%s LIKE %s', $a, $this->input($b = "%$b%"));
}
function __in($a, $b) {
if (is_array($b)) {
$vals = array_map(array($this, 'input'), $b);
$b = implode(', ', $vals);
}
else {
$b = $this->input($b);
}
function __isnull($a, $b) {
return $b
? sprintf('%s IS NULL', $a)
: sprintf('%s IS NOT NULL', $a);
}
function compileJoin($tip, $model, $alias, $info, $extra=false) {
$constraints = array();
$join = ' JOIN ';
if (isset($info['null']) && $info['null'])
$join = ' LEFT'.$join;
if (isset($this->joins[$tip]))
$table = $this->joins[$tip]['alias'];
else
$table = $this->quote($model::$meta['table']);
foreach ($info['constraint'] as $local => $foreign) {
list($rmodel, $right) = explode('.', $foreign);
// Support a constant constraint with
// "'constant'" => "Model.field_name"
if ($local[0] == "'") {
$constraints[] = sprintf("%s.%s = %s",
$alias, $this->quote($right),
$this->input(trim($local, '\'"'), self::SLOT_JOINS)
);
}
else {
$constraints[] = sprintf("%s.%s = %s.%s",
$table, $this->quote($local), $alias,
$this->quote($right)
);
}
// Support extra join constraints
if ($extra instanceof Q) {
$constraints[] = $this->compileQ($extra, $model, self::SLOT_JOINS);
}
return $join.$this->quote($rmodel::$meta['table'])
.' '.$alias.' ON ('.implode(' AND ', $constraints).')';
/**
* input
*
* Generate a parameterized input for a database query. Input value is
* received by reference to avoid copying.
*
* Parameters:
* $what - (mixed) value to be sent to the database. No escaping is
* necessary. Pass a raw value here.
* $slot - (int) clause location of the input in compiled SQL statement.
* Currently, SLOT_JOINS and SLOT_WHERE is supported. SLOT_JOINS
* inputs are inserted ahead of the SLOT_WHERE inputs as the joins
* come logically before the where claused in the finalized
* statement.
*
* Returns:
* (string) token to be placed into the compiled SQL statement. For
* MySQL, this is always the string '?'.
*/
function input(&$what, $slot=false) {
if ($what instanceof QuerySet) {
$q = $what->getQuery(array('nosort'=>true));
$this->params = array_merge($q->params);
elseif ($what instanceof SqlFunction) {
return $what->toSql($this);
switch ($slot) {
case self::SLOT_JOINS:
// This should be inserted before the WHERE inputs
array_splice($this->params, $this->input_join_count++, 0,
array($what));
break;
default:
$this->params[] = $what;
}
}
function quote($what) {
return "`$what`";
}
/**
* getWhereClause
*
* This builds the WHERE ... part of a DML statement. This should be
* called before ::getJoins(), because it may add joins into the
* statement based on the relationships used in the where clause
*/
protected function getWhereHavingClause($queryset) {
$constraints = $this->compileConstraints($queryset->constraints, $model);
$where = $having = array();
foreach ($constraints as $C) {
if ($C->type == CompiledExpression::TYPE_WHERE)
$where[] = $C;
else
$having[] = $C;
}
$where = ' WHERE '.implode(' AND ', $where);
if ($having)
$having = ' HAVING '.implode(' AND ', $having);
return array($where ?: '', $having ?: '');
}
function compileCount($queryset) {
$model = $queryset->model;
$table = $model::$meta['table'];
list($where, $having) = $this->getWhereHavingClause($queryset);
$sql = 'SELECT COUNT(*) AS count FROM '.$this->quote($table).$joins.$where;
$exec = new MysqlExecutor($sql, $this->params);
$row = $exec->getArray();
return $row['count'];
}
function compileSelect($queryset) {
$model = $queryset->model;
// Use an alias for the root model table
$this->joins[''] = array('alias' => ($rootAlias = $this->nextAlias()));
// Compile the WHERE clause
$this->annotations = $queryset->annotations ?: array();
list($where, $having) = $this->getWhereHavingClause($queryset);
// Compile the ORDER BY clause
if ($queryset->ordering && !isset($this->options['nosort'])) {
$orders = array();
foreach ($queryset->ordering as $sort) {
$dir = 'ASC';
if ($sort[0] == '-') {
$dir = 'DESC';
$sort = substr($sort, 1);
}
list($field) = $this->getField($sort, $model);
// TODO: Throw exception if $field can be indentified as
// invalid
$orders[] = $field.' '.$dir;
}
$sort = ' ORDER BY '.implode(', ', $orders);
}
// Compile the field listing
$table = $this->quote($model::$meta['table']).' '.$rootAlias;
$defer = $queryset->defer ?: array();
// Add local fields first
$model::_inspect();
foreach ($model::$meta['fields'] as $f) {
// Handle deferreds
if (isset($defer[$f]))
continue;
$fields[] = $rootAlias . '.' . $this->quote($f);
$fieldMap[] = array($theseFields, $model);
// Add the JOINs to this query
foreach ($queryset->related as $sr) {
// XXX: Sort related by the paths so that the shortest paths
// are resolved first when building out the models.
$full_path = '';
$parts = array();
// Track each model traversal and fetch data for each of the
// models in the path of the related table
foreach (explode('__', $sr) as $field) {
$full_path .= $field;
$parts[] = $field;
list($alias, $fmodel) = $this->getField($full_path, $model,
array('table'=>true, 'model'=>true));
$fmodel::_inspect();
foreach ($fmodel::$meta['fields'] as $f) {
// Handle deferreds
if (isset($defer[$sr . '__' . $f]))
continue;
$fields[] = $alias . '.' . $this->quote($f);
$theseFields[] = $f;
$fieldMap[] = array($theseFields, $fmodel, $parts);
$full_path .= '__';
}
}
}
// Support retrieving only a list of values rather than a model
elseif ($queryset->values) {
list($f) = $this->getField($v, $model);
if ($f instanceof SqlFunction)
$fields[] = $f->toSql($this, $model);
else
$fields[] = $f;
}
// Simple selection from one table
else {
if ($queryset->defer) {
foreach ($model::$meta['fields'] as $f) {
if (isset($queryset->defer[$f]))
continue;
$fields[] = $rootAlias .'.'. $this->quote($f);
}
}
else {
$fields[] = $rootAlias.'.*';
// Add in annotations
if ($queryset->annotations) {
foreach ($queryset->annotations as $A) {
$fields[] = $T = $A->toSql($this, $model, true);
// TODO: Add to last fieldset in fieldMap
if ($fieldMap)
$fieldMap[0][0][] = $A->getAlias();
}
$group_by = array();
foreach ($model::$meta['pk'] as $pk)
$group_by[] = $rootAlias .'.'. $pk;
if ($group_by)
$group_by = ' GROUP BY '.implode(',', $group_by);
}
$sql = 'SELECT '.implode(', ', $fields).' FROM '
.$table.$joins.$where.$group_by.$having.$sort;
if ($queryset->limit)
$sql .= ' LIMIT '.$queryset->limit;
if ($queryset->offset)
$sql .= ' OFFSET '.$queryset->offset;
switch ($queryset->lock) {
case QuerySet::LOCK_EXCLUSIVE:
$sql .= ' FOR UPDATE';
break;
case QuerySet::LOCK_SHARED:
$sql .= ' LOCK IN SHARE MODE';
break;
}
return new MysqlExecutor($sql, $this->params, $fieldMap);
function __compileUpdateSet($model, array $pk) {
$fields = array();
foreach ($model->dirty as $field=>$old) {
if ($model->__new__ or !in_array($field, $pk)) {
$fields[] = sprintf('%s = %s', $this->quote($field),
$this->input($model->get($field)));
}
}
return ' SET '.implode(', ', $fields);
}
function compileUpdate(VerySimpleModel $model) {
$pk = $model::$meta['pk'];
$sql = 'UPDATE '.$this->quote($model::$meta['table']);
$sql .= $this->__compileUpdateSet($model, $pk);
// Support PK updates
$criteria = array();
foreach ($pk as $f) {
$criteria[$f] = @$model->dirty[$f] ?: $model->get($f);
}
$sql .= ' WHERE '.$this->compileQ(new Q($criteria), $model);
$sql .= ' LIMIT 1';
return new MySqlExecutor($sql, $this->params);
}
function compileInsert(VerySimpleModel $model) {
$pk = $model::$meta['pk'];
$sql = 'INSERT INTO '.$this->quote($model::$meta['table']);
$sql .= $this->__compileUpdateSet($model, $pk);
return new MySqlExecutor($sql, $this->params);
function compileDelete($model) {
$table = $model::$meta['table'];
$where = ' WHERE '.implode(' AND ',
$this->compileConstraints(array(new Q($model->pk)), $model));
$sql = 'DELETE FROM '.$this->quote($table).$where.' LIMIT 1';
return new MySqlExecutor($sql, $this->params);
function compileBulkDelete($queryset) {
$model = $queryset->model;
$table = $model::$meta['table'];
list($where, $having) = $this->getWhereHavingClause($queryset);
$joins = $this->getJoins();
$sql = 'DELETE '.$this->quote($table).'.* FROM '
.$this->quote($table).$joins.$where;
return new MysqlExecutor($sql, $this->params);
function compileBulkUpdate($queryset, array $what) {
$model = $queryset->model;
$table = $model::$meta['table'];
$set = array();
foreach ($what as $field=>$value)
$set[] = sprintf('%s = %s', $this->quote($field), $this->input($value));
$set = implode(', ', $set);
list($where, $having) = $this->getWhereHavingClause($queryset);
$joins = $this->getJoins();
$sql = 'UPDATE '.$this->quote($table).' SET '.$set.$joins.$where;
return new MysqlExecutor($sql, $this->params);
}
// Returns meta data about the table used to build queries
function inspectTable($table) {
static $cache = array();
// XXX: Assuming schema is not changing — add support to track
// current schema
if (isset($cache[$table]))
return $cache[$table];
$sql = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS '
.'WHERE TABLE_NAME = '.db_input($table).' AND TABLE_SCHEMA = DATABASE() '
.'ORDER BY ORDINAL_POSITION';
$ex = new MysqlExecutor($sql, array());
$columns = array();
while (list($column) = $ex->getRow()) {
$columns[] = $column;
}
return $cache[$table] = $columns;
}
}
class MysqlExecutor {
var $stmt;
var $fields = array();
var $sql;
var $params;
// Array of [count, model] values representing which fields in the
// result set go with witch model. Useful for handling select_related
// queries
var $map;
function __construct($sql, $params, $map=null) {
$this->sql = $sql;
$this->params = $params;
$this->map = $map;
}
function getMap() {
return $this->map;
$this->execute();
$this->_setup_output();
}
function execute() {
if (!($this->stmt = db_prepare($this->sql)))
throw new Exception('Unable to prepare query: '.db_error()
.' '.$this->sql);
if (count($this->params))
$this->_bind($this->params);
if (!$this->stmt->execute() || ! $this->stmt->store_result()) {
throw new OrmException('Unable to execute query: ' . $this->stmt->error);
}
return true;
}
function _bind($params) {
if (count($params) != $this->stmt->param_count)
throw new Exception(__('Parameter count does not match query'));
if (is_int($p) || is_bool($p))
elseif (is_float($p))
$types .= 'd';
// TODO: Emit error if param is null
array_unshift($ps, $types);
call_user_func_array(array($this->stmt,'bind_param'), $ps);
}
function _setup_output() {
if (!($meta = $this->stmt->result_metadata()))
throw new OrmException('Unable to fetch statment metadata: ', $this->stmt->error);
$this->fields = $meta->fetch_fields();
}
// Iterator interface
function rewind() {
if (!isset($this->stmt))
$this->_prepare();
$this->stmt->data_seek(0);
}
function next() {
$status = $this->stmt->fetch();
if ($status === false)
throw new OrmException($this->stmt->error);
elseif ($status === null) {
$this->close();
return false;
}
return true;
}
function getArray() {
$output = array();
$variables = array();
if (!isset($this->stmt))
$this->_prepare();
foreach ($this->fields as $f)
$variables[] = &$output[$f->name]; // pass by reference
if (!call_user_func_array(array($this->stmt, 'bind_result'), $variables))
throw new OrmException('Unable to bind result: ' . $this->stmt->error);
if (!$this->next())
return false;
return $output;
}
function getRow() {
$output = array();
$variables = array();
if (!isset($this->stmt))
$this->_prepare();
foreach ($this->fields as $f)
$variables[] = &$output[]; // pass by reference
if (!call_user_func_array(array($this->stmt, 'bind_result'), $variables))
throw new OrmException('Unable to bind result: ' . $this->stmt->error);
if (!$this->next())
return false;
return $output;
}
function close() {
if (!$this->stmt)
return;
$this->stmt->close();
$this->stmt = null;
}
function affected_rows() {
return $this->stmt->affected_rows;
}
function insert_id() {
return $this->stmt->insert_id;
}
function __toString() {
return $this->sql;
}
}
class Q {
const NEGATED = 0x0001;
const ANY = 0x0002;
var $constraints;
var $flags;
var $negated = false;
var $ored = false;
function __construct($filter, $flags=0) {
if (!is_array($filter))
$filter = array($filter);
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
$this->constraints = $filter;
$this->negated = $flags & self::NEGATED;
$this->ored = $flags & self::ANY;
}
function isNegated() {
return $this->negated;
}
function isOred() {
return $this->ored;
}
function negate() {
$this->negated = !$this->negated;
return $this;
}
static function not(array $constraints) {
return new static($constraints, self::NEGATED);
}
static function any(array $constraints) {
return new static($constraints, self::ANY);