<?php
 namespace Moto\Validator\Db; use Moto; use Zend\Validator; class NoRecordExists extends Validator\Db\NoRecordExists { protected $_context = array(); protected $_where = null; public function __construct($options = null) { parent::__construct($options); if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (is_array($options)) { if (!empty($options['where'])) { $this->_where = $options['where']; } } if (null === $this->adapter) { $this->adapter = Moto\Config::get('databaseAdapter'); } } public function getSelect() { if (is_array($this->exclude) && $this->exclude['value'] === '@equalTo') { if (array_key_exists($this->exclude['field'], $this->_context)) { $this->exclude['value'] = $this->_context[ $this->exclude['field'] ]; } else { $this->setExclude(null); } } $select = parent::getSelect(); if (!empty($this->_where)) { foreach ($this->_where as $key => $value) { if (!array_key_exists($key, $this->_context)) { $select->where->equalTo($key, $value); continue; } switch($value) { case '@equalTo': $select->where->equalTo($key, $this->_context[$key]); break; case '@notEqualTo': $select->where->notEqualTo($key, $this->_context[$key]); break; default: $select->where->equalTo($key, $value); break; } } $this->_where = null; $this->select = $select; } return $select; } public function isValid($value, $context = array()) { $this->_context = $context; return parent::isValid($value, $context); } }