ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Name.php
1 <?php
30  extends Zend_Validate_Abstract
31 {
32  const NAME_EMPTY = 'databaseNameEmpty';
33  const RENAME = 'databaseRename';
34  const EXISTS = 'databaseExists';
35 
39  protected $_messageTemplates = array(
40  self::NAME_EMPTY => "Database name can not be empty",
41  self::RENAME => 'Cannot rename %value% database',
42  self::EXISTS => "Database with name %value% alteady exists"
43  );
44 
51  public function isValid($value)
52  {
53  $schema = null;
54  if ($value instanceof ZendDbSchema_Db_Schema_Database) {
55  $schema = $value;
56  $value = $schema->getName();
57  }
58  if (empty($value)) {
59  $this->_error(self::NAME_EMPTY);
60  return false;
61  }
62  if ($schema && $value !== $schema->getOriginName()) {
63  if ($schema->isExist()) {
64  $this->_error(self::RENAME, $schema->getOriginName());
65  return false;
66  } elseif ($schema->getAdapter()->hasDatabase($value)) {
67  $this->_error(self::EXISTS, $value);
68  return false;
69  }
70  }
71  return true;
72  }
73 }