lithium\data\source\MongoDb::_init()
Overrides
lithium\core\Object::_init()
Initializer. Adds operator handlers which will later allow to correctly cast any values.
Returns
voidSource
protected function _init() {
parent::_init();
$this->_operators += array(
'like' => function($key, $value) {
return new MongoRegex($value);
},
'$exists' => function($key, $value) {
return array('$exists' => (boolean) $value);
},
'$type' => function($key, $value) {
return array('$type' => (integer) $value);
},
'$mod' => function($key, $value) {
$value = (array) $value;
return array('$mod' => array(current($value), next($value) ?: 0));
},
'$size' => function($key, $value) {
return array('$size' => (integer) $value);
},
'$elemMatch' => function($operator, $values, $options = array()) {
$options += array(
'castOpts' => array(),
'field' => ''
);
$options['castOpts'] += array('pathKey' => $options['field']);
$values = (array) $values;
if (empty($options['castOpts']['schema'])) {
return array('$elemMatch' => $values);
}
foreach ($values as $key => &$value) {
$value = $options['castOpts']['schema']->cast(
null, $key, $value, $options['castOpts']
);
}
return array('$elemMatch' => $values);
}
);
}