Browse Source

[ZF-7953] Zend_Validate_Db:

- added getter and setter for all options

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18417 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
35848975ac

+ 1 - 2
documentation/manual/en/module_specs/Zend_Validate-Db.xml

@@ -157,8 +157,7 @@ if ($validator->isValid($username)) {
         <title>Database Adapters</title>
         <title>Database Adapters</title>
 
 
         <para>
         <para>
-            You can also specify an adapter, as the fourth parameter when
-            instantiating your validator, this will allow you to work with
+            You can also specify an adapter. This will allow you to work with
             applications using multiple database adapters, or where you have not
             applications using multiple database adapters, or where you have not
             set a default adapter. As in the example below:
             set a default adapter. As in the example below:
         </para>
         </para>

+ 120 - 10
library/Zend/Validate/Db/Abstract.php

@@ -120,26 +120,136 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
         }
         }
 
 
         if (array_key_exists('adapter', $options)) {
         if (array_key_exists('adapter', $options)) {
-            if (!($options['adapter'] instanceof Zend_Db_Adapter_Abstract)) {
-                require_once 'Zend/Validate/Exception.php';
-                throw new Zend_Validate_Exception('Adapter option must be a database adapter!');
-            }
-
-            $this->_adapter = $options['adapter'];
+            $this->setAdapter($options['adapter']);
         }
         }
 
 
         if (array_key_exists('exclude', $options)) {
         if (array_key_exists('exclude', $options)) {
-            $this->_exclude = $options['exclude'];
+            $this->setExclude($options['exclude']);
         }
         }
 
 
-        $this->_field   = (string) $options['field'];
+        $this->setField($options['field']);
         if (array_key_exists('table', $options)) {
         if (array_key_exists('table', $options)) {
-            $this->_table = (string) $options['table'];
+            $this->setTable($options['table']);
         }
         }
 
 
         if (array_key_exists('schema', $options)) {
         if (array_key_exists('schema', $options)) {
-            $this->_schema = $options['schema'];
+            $this->setSchema($options['schema']);
+        }
+    }
+
+    /**
+     * Returns the set adapter
+     *
+     * @return Zend_Db_Adapter
+     */
+    public function getAdapter()
+    {
+        return $this->_adapter;
+    }
+
+    /**
+     * Sets a new database adapter
+     *
+     * @param  Zend_Db_Adapter_Abstract $adapter
+     * @return Zend_Validate_Db_Abstract
+     */
+    public function setAdapter($adapter)
+    {
+        if (!($adapter instanceof Zend_Db_Adapter_Abstract)) {
+            require_once 'Zend/Validate/Exception.php';
+            throw new Zend_Validate_Exception('Adapter option must be a database adapter!');
         }
         }
+
+        $this->_adapter = $adapter;
+        return $this;
+    }
+
+    /**
+     * Returns the set exclude clause
+     *
+     * @return string|array
+     */
+    public function getExclude()
+    {
+        return $this->_exclude;
+    }
+
+    /**
+     * Sets a new exclude clause
+     *
+     * @param string|array $exclude
+     * @return Zend_Validate_Db_Abstract
+     */
+    public function setExclude($exclude)
+    {
+        $this->_exclude = $exclude;
+        return $this;
+    }
+
+    /**
+     * Returns the set field
+     *
+     * @return string|array
+     */
+    public function getField()
+    {
+        return $this->_field;
+    }
+
+    /**
+     * Sets a new field
+     *
+     * @param string $field
+     * @return Zend_Validate_Db_Abstract
+     */
+    public function setField($field)
+    {
+        $this->_field = (string) $field;
+        return $this;
+    }
+
+    /**
+     * Returns the set table
+     *
+     * @return string
+     */
+    public function getTable()
+    {
+        return $this->_table;
+    }
+
+    /**
+     * Sets a new table
+     *
+     * @param string $table
+     * @return Zend_Validate_Db_Abstract
+     */
+    public function setTable($table)
+    {
+        $this->_table = (string) $table;
+        return $this;
+    }
+
+    /**
+     * Returns the set schema
+     *
+     * @return string
+     */
+    public function getSchema()
+    {
+        return $this->_schema;
+    }
+
+    /**
+     * Sets a new schema
+     *
+     * @param string $schema
+     * @return Zend_Validate_Db_Abstract
+     */
+    public function setSchema($schema)
+    {
+        $this->_schema = $schema;
+        return $this;
     }
     }
 
 
     /**
     /**