Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Validate_Db_Abstract Class Reference
Inheritance diagram for Zend_Validate_Db_Abstract:
Zend_Validate_Abstract Zend_Validate_Interface Zend_Validate_Db_NoRecordExists Zend_Validate_Db_RecordExists

Public Member Functions

 __construct ($options)
 
 getAdapter ()
 
 setAdapter ($adapter)
 
 getExclude ()
 
 setExclude ($exclude)
 
 getField ()
 
 setField ($field)
 
 getTable ()
 
 setTable ($table)
 
 getSchema ()
 
 setSchema ($schema)
 
 setSelect ($select)
 
 getSelect ()
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 

Data Fields

const ERROR_NO_RECORD_FOUND = 'noRecordFound'
 
const ERROR_RECORD_FOUND = 'recordFound'
 

Protected Member Functions

 _query ($value)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_messageTemplates
 
 $_schema = null
 
 $_table = ''
 
 $_field = ''
 
 $_exclude = null
 
 $_adapter = null
 
 $_select
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 36 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options)

Provides basic configuration for use with Zend_Validate_Db Validators Setting $exclude allows a single record to be excluded from matching. Exclude can either be a String containing a where clause, or an array with field and value keys to define the where clause added to the sql. A database adapter may optionally be supplied to avoid using the registered default adapter.

The following option keys are supported: 'table' => The database table to validate against 'schema' => The schema keys 'field' => The field to check for a match 'exclude' => An optional where clause or field/value pair to exclude from the query 'adapter' => An optional database adapter to use

Parameters
array | Zend_Config$optionsOptions to use for this validator
Exceptions
Zend_Validate_Exception

Definition at line 102 of file Abstract.php.

103  {
104  if ($options instanceof Zend_Db_Select) {
105  $this->setSelect($options);
106  return;
107  }
108  if ($options instanceof Zend_Config) {
109  $options = $options->toArray();
110  } else if (func_num_args() > 1) {
111  $options = func_get_args();
112  $temp['table'] = array_shift($options);
113  $temp['field'] = array_shift($options);
114  if (!empty($options)) {
115  $temp['exclude'] = array_shift($options);
116  }
117 
118  if (!empty($options)) {
119  $temp['adapter'] = array_shift($options);
120  }
121 
122  $options = $temp;
123  }
124 
125  if (!array_key_exists('table', $options) && !array_key_exists('schema', $options)) {
126  #require_once 'Zend/Validate/Exception.php';
127  throw new Zend_Validate_Exception('Table or Schema option missing!');
128  }
129 
130  if (!array_key_exists('field', $options)) {
131  #require_once 'Zend/Validate/Exception.php';
132  throw new Zend_Validate_Exception('Field option missing!');
133  }
134 
135  if (array_key_exists('adapter', $options)) {
136  $this->setAdapter($options['adapter']);
137  }
138 
139  if (array_key_exists('exclude', $options)) {
140  $this->setExclude($options['exclude']);
141  }
142 
143  $this->setField($options['field']);
144  if (array_key_exists('table', $options)) {
145  $this->setTable($options['table']);
146  }
147 
148  if (array_key_exists('schema', $options)) {
149  $this->setSchema($options['schema']);
150  }
151  }

Member Function Documentation

◆ _query()

_query (   $value)
protected

Run query and returns matches, or null if no matches are found.

Parameters
String$value
Returns
Array when matches are found.

Run query

Definition at line 341 of file Abstract.php.

342  {
343  $select = $this->getSelect();
347  $result = $select->getAdapter()->fetchRow(
348  $select,
349  array('value' => $value), // this should work whether db supports positional or named params
351  );
352 
353  return $result;
354  }
const FETCH_ASSOC
Definition: Db.php:142
$value
Definition: gender.phtml:16

◆ getAdapter()

getAdapter ( )

Returns the set adapter

Exceptions
Zend_Validate_Exception
Returns
Zend_Db_Adapter

Check for an adapter being defined. if not, fetch the default adapter.

Definition at line 159 of file Abstract.php.

160  {
164  if ($this->_adapter === null) {
165  $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
166  if (null === $this->_adapter) {
167  #require_once 'Zend/Validate/Exception.php';
168  throw new Zend_Validate_Exception('No database adapter present');
169  }
170  }
171  return $this->_adapter;
172  }
static getDefaultAdapter()
Definition: Abstract.php:571

◆ getExclude()

getExclude ( )

Returns the set exclude clause

Returns
string|array

Definition at line 197 of file Abstract.php.

198  {
199  return $this->_exclude;
200  }

◆ getField()

getField ( )

Returns the set field

Returns
string|array

Definition at line 219 of file Abstract.php.

220  {
221  return $this->_field;
222  }

◆ getSchema()

getSchema ( )

Returns the set schema

Returns
string

Definition at line 263 of file Abstract.php.

264  {
265  return $this->_schema;
266  }

◆ getSelect()

getSelect ( )

Gets the select object to be used by the validator. If no select object was supplied to the constructor, then it will auto-generate one from the given table, schema, field, and adapter options.

Returns
Zend_Db_Select The Select object which will be used

Build select object

Definition at line 305 of file Abstract.php.

306  {
307  if (null === $this->_select) {
308  $db = $this->getAdapter();
312  $select = new Zend_Db_Select($db);
313  $select->from($this->_table, array($this->_field), $this->_schema);
314  if ($db->supportsParameters('named')) {
315  $select->where($db->quoteIdentifier($this->_field, true).' = :value'); // named
316  } else {
317  $select->where($db->quoteIdentifier($this->_field, true).' = ?'); // positional
318  }
319  if ($this->_exclude !== null) {
320  if (is_array($this->_exclude)) {
321  $select->where(
322  $db->quoteIdentifier($this->_exclude['field'], true) .
323  ' != ?', $this->_exclude['value']
324  );
325  } else {
326  $select->where($this->_exclude);
327  }
328  }
329  $select->limit(1);
330  $this->_select = $select;
331  }
332  return $this->_select;
333  }

◆ getTable()

getTable ( )

Returns the set table

Returns
string

Definition at line 241 of file Abstract.php.

242  {
243  return $this->_table;
244  }

◆ setAdapter()

setAdapter (   $adapter)

Sets a new database adapter

Parameters
Zend_Db_Adapter_Abstract$adapter
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_Db_Abstract

Definition at line 181 of file Abstract.php.

182  {
183  if (!($adapter instanceof Zend_Db_Adapter_Abstract)) {
184  #require_once 'Zend/Validate/Exception.php';
185  throw new Zend_Validate_Exception('Adapter option must be a database adapter!');
186  }
187 
188  $this->_adapter = $adapter;
189  return $this;
190  }
$adapter
Definition: webapi_user.php:16

◆ setExclude()

setExclude (   $exclude)

Sets a new exclude clause

Parameters
string | array$exclude
Returns
Zend_Validate_Db_Abstract

Definition at line 208 of file Abstract.php.

209  {
210  $this->_exclude = $exclude;
211  return $this;
212  }

◆ setField()

setField (   $field)

Sets a new field

Parameters
string$field
Returns
Zend_Validate_Db_Abstract

Definition at line 230 of file Abstract.php.

231  {
232  $this->_field = (string) $field;
233  return $this;
234  }

◆ setSchema()

setSchema (   $schema)

Sets a new schema

Parameters
string$schema
Returns
Zend_Validate_Db_Abstract

Definition at line 274 of file Abstract.php.

275  {
276  $this->_schema = $schema;
277  return $this;
278  }

◆ setSelect()

setSelect (   $select)

Sets the select object to be used by the validator

Parameters
Zend_Db_Select$select
Exceptions
Zend_Validate_Exception
Returns
Zend_Validate_Db_Abstract

Definition at line 287 of file Abstract.php.

288  {
289  if (!$select instanceof Zend_Db_Select) {
290  throw new Zend_Validate_Exception('Select option must be a valid ' .
291  'Zend_Db_Select object');
292  }
293  $this->_select = $select;
294  return $this;
295  }

◆ setTable()

setTable (   $table)

Sets a new table

Parameters
string$table
Returns
Zend_Validate_Db_Abstract

Definition at line 252 of file Abstract.php.

253  {
254  $this->_table = (string) $table;
255  return $this;
256  }
$table
Definition: trigger.php:14

Field Documentation

◆ $_adapter

$_adapter = null
protected

Definition at line 77 of file Abstract.php.

◆ $_exclude

$_exclude = null
protected

Definition at line 70 of file Abstract.php.

◆ $_field

$_field = ''
protected

Definition at line 65 of file Abstract.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::ERROR_NO_RECORD_FOUND => "No record matching '%value%' was found",
self::ERROR_RECORD_FOUND => "A record matching '%value%' was found",
)

Definition at line 47 of file Abstract.php.

◆ $_schema

$_schema = null
protected

Definition at line 55 of file Abstract.php.

◆ $_select

$_select
protected

Definition at line 83 of file Abstract.php.

◆ $_table

$_table = ''
protected

Definition at line 60 of file Abstract.php.

◆ ERROR_NO_RECORD_FOUND

const ERROR_NO_RECORD_FOUND = 'noRecordFound'

Error constants

Definition at line 41 of file Abstract.php.

◆ ERROR_RECORD_FOUND

const ERROR_RECORD_FOUND = 'recordFound'

Definition at line 42 of file Abstract.php.


The documentation for this class was generated from the following file: