--- tests/Zend/Db/Table/TableAccountsAutoload.php (revision 0) +++ tests/Zend/Db/Table/TableAccountsAutoload.php (revision 0) @@ -0,0 +1,57 @@ +fetchAll();; + $row = $rowset->current(); + + $this->assertTrue(class_exists('Zend_Db_Table_Row_TestMyRowAutoload', false), + 'Expected TestMyRow class to be loaded (#1)'); + $this->assertTrue(class_exists('Zend_Db_Table_Rowset_TestMyRowsetAutoload', false), + 'Expected TestMyRowset class to be loaded (#1)'); + + } catch(Zend_Exception $e) { + $this->fail('Zend DB Table did not use the autoloader when loading rowset/row classes (#2)'); + } + + spl_autoload_unregister(__CLASS__ . '::autoloaderTest'); + } + + /** + * Helper for autoloader tests + * + * @param string $class + */ + public static function autoloaderTest($class) + { + if (strstr($class, 'Autoload')) { + $parts = explode('_', $class); + include_once(dirname(__FILE__) . '/Autoload/' . $parts[4] . '.php'); + } + } } Index: library/Zend/Db/Table/Rowset/Abstract.php =================================================================== --- library/Zend/Db/Table/Rowset/Abstract.php (revision 14216) +++ library/Zend/Db/Table/Rowset/Abstract.php (working copy) @@ -116,7 +116,9 @@ if (isset($config['rowClass'])) { $this->_rowClass = $config['rowClass']; } - @Zend_Loader::loadClass($this->_rowClass); + if (!class_exists($this->_rowClass)) { + @Zend_Loader::loadClass($this->_rowClass); + } if (isset($config['data'])) { $this->_data = $config['data']; } Index: library/Zend/Db/Table/Row/Abstract.php =================================================================== --- library/Zend/Db/Table/Row/Abstract.php (revision 14216) +++ library/Zend/Db/Table/Row/Abstract.php (working copy) @@ -525,7 +525,9 @@ $pkOld = $this->_getPrimaryKey(false); foreach ($depTables as $tableClass) { try { - @Zend_Loader::loadClass($tableClass); + if (!class_exists($tableClass)) { + @Zend_Loader::loadClass($tableClass); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -603,7 +605,9 @@ $pk = $this->_getPrimaryKey(); foreach ($depTables as $tableClass) { try { + if (!class_exists($tableClass)) { @Zend_Loader::loadClass($tableClass); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -856,7 +860,9 @@ if (is_string($dependentTable)) { try { - @Zend_Loader::loadClass($dependentTable); + if (!class_exists($dependentTable)) { + @Zend_Loader::loadClass($dependentTable); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -909,7 +915,9 @@ if (is_string($parentTable)) { try { - @Zend_Loader::loadClass($parentTable); + if (!class_exists($parentTable)) { + @Zend_Loader::loadClass($parentTable); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -963,7 +971,9 @@ if (is_string($intersectionTable)) { try { - @Zend_Loader::loadClass($intersectionTable); + if (!class_exists($intersectionTable)) { + @Zend_Loader::loadClass($intersectionTable); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -981,7 +991,9 @@ if (is_string($matchTable)) { try { - @Zend_Loader::loadClass($matchTable); + if (!class_exists($matchTable)) { + @Zend_Loader::loadClass($matchTable); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); @@ -1049,7 +1061,9 @@ $rowsetClass = $matchTable->getRowsetClass(); try { - @Zend_Loader::loadClass($rowsetClass); + if (!class_exists($rowsetClass)) { + @Zend_Loader::loadClass($rowsetClass); + } } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; throw new Zend_Db_Table_Row_Exception($e->getMessage()); Index: library/Zend/Db/Table/Abstract.php =================================================================== --- library/Zend/Db/Table/Abstract.php (revision 14216) +++ library/Zend/Db/Table/Abstract.php (working copy) @@ -1165,7 +1165,9 @@ 'stored' => true ); - @Zend_Loader::loadClass($this->_rowsetClass); + if (!class_exists($this->_rowsetClass)) { + @Zend_Loader::loadClass($this->_rowsetClass); + } return new $this->_rowsetClass($data); } @@ -1210,7 +1212,9 @@ 'stored' => true ); - @Zend_Loader::loadClass($this->_rowClass); + if (!class_exists($this->_rowClass)) { + @Zend_Loader::loadClass($this->_rowClass); + } return new $this->_rowClass($data); } @@ -1269,7 +1273,9 @@ 'stored' => false ); - @Zend_Loader::loadClass($this->_rowClass); + if (!class_exists($this->_rowClass)) { + @Zend_Loader::loadClass($this->_rowClass); + } $row = new $this->_rowClass($config); $row->setFromArray($data); return $row; Index: documentation/manual/en/module_specs/Zend_Db_Table_Row.xml =================================================================== --- documentation/manual/en/module_specs/Zend_Db_Table_Row.xml (revision 14216) +++ documentation/manual/en/module_specs/Zend_Db_Table_Row.xml (working copy) @@ -471,6 +471,22 @@ the constructor of a Table object. + + + + Class loading is important when using custom Row classes, you + will need to make sure that the custom classes are loaded and ready for the + table classes to use. + + + All the DB Table classes support the use of autoloading via PHP's SPL Autoload + and will check with the autoloader before trying Zend_Loader::loadClass(). + Therefore, you can make use of the Zend_Loader_Autoloader* components when loading + row classes. + + + + Specifying a custom Row class Index: documentation/manual/en/module_specs/Zend_Db_Table_Rowset.xml =================================================================== --- documentation/manual/en/module_specs/Zend_Db_Table_Rowset.xml (revision 14216) +++ documentation/manual/en/module_specs/Zend_Db_Table_Rowset.xml (working copy) @@ -355,6 +355,22 @@ constructor of a Table object. + + + + Class loading is important when using custom Rowset classes, you + will need to make sure that the custom classes are loaded and ready for the + table classes to use. + + + All the DB Table classes support the use of autoloading via PHP's SPL Autoload + and will check with the autoloader before trying Zend_Loader::loadClass(). + Therefore, you can make use of the Zend_Loader_Autoloader* components when loading + rowset classes. + + + + Specifying a custom Rowset class + + + + Class loading is important when using custom Row and Rowset classes, you + will need to make sure that the custom classes are loaded and ready for the + table classes to use. + + + All the DB Table classes support the use of autoloading via PHP's SPL Autoload + and will check with the autoloader before trying Zend_Loader::loadClass(). + Therefore, you can make use of the Zend_Loader_Autoloader* components when loading + custom Row and Rowset classes. + + + + For more information on the Row and Rowset classes, see and .