lithium\data\source\MongoDb::_init()

protected method

Initializer. Adds operator handlers which will later allow to correctly cast any values. Constructs a DSN from configuration, if not given.

Returns

void

Source

	protected function _init() {
		parent::_init();

		$this->_config = Set::merge($this->_config, $this->_formatConfig($this->_config));

		$this->_operators += [
			'like' => function($key, $value) {
				return new Regex($value);
			},
			'$exists' => function($key, $value) {
				return ['$exists' => (boolean) $value];
			},
			'$type' => function($key, $value) {
				return ['$type' => (integer) $value];
			},
			'$mod' => function($key, $value) {
				$value = (array) $value;
				return ['$mod' => [current($value), next($value) ?: 0]];
			},
			'$size' => function($key, $value) {
				return ['$size' => (integer) $value];
			},
			'$elemMatch' => function($operator, $values, $options = []) {
				$options += [
					'castOpts' => [],
					'field' => ''
				];
				$options['castOpts'] += ['pathKey' => $options['field']];
				$values = (array) $values;

				if (empty($options['castOpts']['schema'])) {
					return ['$elemMatch' => $values];
				}
				foreach ($values as $key => &$value) {
					$value = $options['castOpts']['schema']->cast(
						null, $key, $value, $options['castOpts']
					);
				}
				return ['$elemMatch' => $values];
			}
		];

		if ($this->_config['autoConnect'] !== false) {
			$this->connect();
		}
	}