ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Type.php
1 <?php
30  extends Zend_Validate_Abstract
31 {
32  const NAME_EMPTY = 'indexTypeEmpty';
33  const RENAME = 'indexTypeRename';
34  const INVALID = 'indexTypeInvalid';
35 
39  protected $_messageTemplates = array(
40  self::NAME_EMPTY => "Index type can not be empty",
41  self::INVALID => "Index type %value% is not a valid type",
42  self::RENAME => "Cannot change type of existing index"
43  );
44 
48  protected $_indexesTypes = array(
49  'FULLTEXT',
50  'UNIQUE'
51  );
52 
59  public function isValid($value)
60  {
61  $schema = null;
62  if ($value instanceof ZendDbSchema_Db_Schema_Table_Index) {
63  $schema = $value;
64  $value = $schema->__get('type');
65  }
66  if (empty($value)) {
67  $this->_error(self::NAME_EMPTY);
68  return false;
69  }
70  if ($schema && $schema->isDirty('type')) {
71  if ($schema->isExist()) {
72  $this->_error(self::RENAME, $value);
73  return false;
74  }
75  if (!in_array(strtoupper($value), $this->_indexesTypes)) {
76  $this->_error(self::INVALID, $value);
77  return false;
78  }
79  }
80  return true;
81  }
82 }